Redux-Form initial values from

前端 未结 6 1062
名媛妹妹
名媛妹妹 2020-12-08 09:16

I\'m trying to fill the profile form with data from API. Unfortunately redux-form doesn\'t want to cooperate with me in this case. For some reason fields stays empty whateve

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 09:50

    If the enableReinitialize : true trick does not work, you can update each field when the initialValues prop changes.

    componentWillReceiveProps(nextProps) {
        const { change, initialValues } = this.props
        const values = nextProps.initialValues;
    
        if(initialValues !== values){
            for (var key in values) {
                if (values.hasOwnProperty(key)) {
                    change(key,values[key]);
                }
            }
        }
    }
    

    I have never worked with FieldsArray but I assume this would not work here.

提交回复
热议问题