问题
i have a component , where i am having a wizard form , first tab will ask the mark details of student and second tab will ask the basic details of the student. so from cookie i am getting the username on the second tab like auto fill.
so my entire component consist of index.js , wizardformmarks , wizardformdetails.
index.js
render(){
return(
<WizardFormMarks initialValues={this.props.initialValues}/>
<WizardFormDetails initialValues={this.props.initialValues}/>
)
}
const mapStateToProps = (state) => {
let initialValuesCopy = state.initialValues || {}
initialValuesCopy.username = extractValue("username") // from cookie
return {
initialValues: initialValuesCopy
};
}
const mapDispatchToProps = (dispatch) => ({
// fetching the user details since same component is used for editing also , so to fetch details this api will perform only if in route params are there like localhost:3000/student/test1,
})
Student = connect(
mapStateToProps,
mapDispatchToProps
)(Student);
export default Student
wizardformmarks.js
export default reduxForm({
form: 'wizard', //
destroyOnUnmount: false,
forceUnregisterOnUnmount: true,
enableReinitialize: true
})(
connect(
mapStateToProps,
mapDispatchToProps
)(WizardFormMarks)
);
wizardformdetails.js
render(){
return(
<div>
<Field
name="username"
type="text"
component={customField}
label="Enter your name.."
disabledStatus={true}
/>
</div>
)
}
export default reduxForm({
form: 'wizard',
destroyOnUnmount: false,
forceUnregisterOnUnmount: true,
})(WizardFormDetails);
Also the same component is used of edit and create. The edit, create and while editing if i move to some other component the data persist. But while creating the data is not persisting if i go to another component and comes back. Even though destroyOnUnmount is set as false.
How can i persist the data. Also the initialValues redux default state is ''. thats why i check and assign an object.
来源:https://stackoverflow.com/questions/54122839/redux-form-data-not-persisting-once-componentunmounts