How to properly set default values using redux-forms?

爷,独闯天下 提交于 2019-12-05 03:53:34

You're not able to edit the fields because you're initializing on every render if those props are present. To use initialize, you would want to do that in componentDidMount rather than in your render method.

An alternative approach would be to wrap the form component and supply initialValues based on those props.

const Wrapper = ({ location: { query }, ...props }) => {
  class LoginPage extends Component {
    ...
  }
  const WrappedForm = reduxForm({
    form: 'the-form',
    validate,
    initialValues: {
      firstname: query.firstname,
      lastname: query.lastname,
      birthday: query.dob
    }
   })(LoginPage);
   return <WrappedForm {...props} />;
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!