2017-12-02 4 views
2

참조를 작성할 사용할 때 업데이트되지 initialValues ​​: 나는 프로필 양식을 구현하기 위해 노력하고 https://redux-form.com/6.7.0/examples/initializefromstate/돌아 오는 양식 -

그 API를 엔드 포인트에서 페치 초기 데이터로 업데이트됩니다.

위의 redux-form 예제를 참조 할 때 예제를 사용할 수있었습니다. 그러나 내가 리팩터링 할 때 'initialValues'를 사용하여 필드에 삽입되지 않습니다.

이 코드는 작동하지 않지만 initialValues에는 데이터가 있지만 양식 필드에는 삽입되지 않습니다.

export default compose(
    reduxForm({ 
     form: 'initializeFromState', 
     enableReinitialize : true 
    }), 
    connect(state => ({ 
     initialValues: state.profile, // pull initial values from account reducer 
    }), actions) 
)(EditProfile); 

그러나이 코드는 참고 예제에서 약간 수정되었습니다. 'initialValues'에는 데이터도 포함됩니다.

EditProfile = reduxForm({ 
    form: 'initializeFromState', 
    enableReinitialize: true 
})(EditProfile); 

EditProfile = connect(
    state => ({ 
     initialValues: state.profile, 
    }), 
    actions, 
)(EditProfile); 

export default EditProfile; 

나처럼 보이지만 어쩌면 이처럼 작성할 수 없습니까?

답변

3

compose에 인수를 잘못 전달했습니다. 구성된 함수는 끝에서 처음으로 실행됩니다. 따라서 두 번째 예와 동일한 순서로 주문을 취소해야합니다.

export default compose(
    connect(state => ({ 
     initialValues: state.profile, // pull initial values from account reducer 
    }), actions), 
    reduxForm({ 
     form: 'initializeFromState', 
     enableReinitialize : true 
    }) 
)(EditProfile);