unable set a default value in redux-form w. react

前端 未结 1 528
無奈伤痛
無奈伤痛 2021-01-13 11:12

I\'m unable to set a default value of a form w/redux-form. The result I\'m looking for is an editable text field to later to submit to the database. i.e. updating an email a

1条回答
  •  北恋
    北恋 (楼主)
    2021-01-13 11:42

    You can supply initialValues in reduxForm's mapStateToProps:

    const mapFormToProps = {
      form: 'Profile',
      fields,
      validate
    };
    
    const mapStateToProps = (state, ownProps) => ({
      initialValues: {
        name: ownProps.userInfo.name
      }
    });
    
    reduxForm(
      mapFormToProps,
      mapStateToProps
    )(Profile)
    

    Then just bind like so: .

    0 讨论(0)
提交回复
热议问题