I have a big React form and I need to save values inserted by the user, so he can change page and then go back to the form and finish it later.
I'm using formik for the form and I tried to save formik.values in a redux state when the form changes, but when I go back to the page, the state has empty values.
I tried something like this, but it's not working properly:
const savedForm = useSelector(
(state) => state.form.savedForm
);
const formik = useFormik({
initialValues: {
instrument: savedForm.intrument || "",
client: savedForm.client|| "",
},
validationSchema: validation,
onSubmit: (values) => {
console.log(values);
},
});
useEffect(() => {
dispatch(saveForm(formik.values))
}, [formik.values])
Does someone know how to do this? I didn't want to use local/session storage to save the form if possible.
Thanks