I need to persist step form's data as if the user clicks on other step. So during unmounting of step form component, I need to update the state to REDUX store
Issue
The state seems to be resetting to default as soon as I am accessing it while unmounting;
// local state
const [state, setState] = React.useState({
named: [{ id: uuid(), value: '', name: '', type: ' ' }], // initial state
});
React.useEffect(() => {
// update redux state before unmounting
return () => {
// sets itself to initial state ignoring what user has typed
console.log(state); // prints [{ id: uuid(), value: '', name: '', type: ' ' }]
updateStepThreeReduxState(state); // redux action
};
}, []);
Is there any way we can get an access to the state just before unmouting ??