Using redux-form I'm losing focus after typing the first character

后端 未结 7 670
甜味超标
甜味超标 2020-12-24 12:40

I\'m using redux-form and on blur validation. After I type the first character into an input element, it loses focus and I have to click in it again to continue

7条回答
  •  庸人自扰
    2020-12-24 13:23

    This happens because you're re-defining renderField as a new component every time you render which means it looks like a new component to React so it'll unmount the original one and re-mounts the new one.

    You'll need to hoist it up:

    const renderField = ({ input, label, type, meta: { touched, invalid, error } }) => (
          
    {touched ? error: ''}
    ); class SignIn extends Component { ... render() { const { message, handleSubmit, prestine, reset, submitting } = this.props; return (

    Please sign in

    {this.renderAlert()}
    ); } } ...

提交回复
热议问题