formik-persist icon indicating copy to clipboard operation
formik-persist copied to clipboard

Deleting localStorage entry

Open JoaoCnh opened this issue 6 years ago • 6 comments

I'm using Persist in forms and I want them persisted while the user hasn't submitted the form. Once the user submits the form it should clean up. So what I did was onSubmit I use localStorage.removeItem("form-name");

That works and removes but just ms later it creates a new entry in localStorage again.

My specific state structure is a simple success boolean. If true it returns just a success component and if not renders the form.

What could be happening? I assumed that without any <Persist /> component rendering it wouldn't submit more entries to localStorage

JoaoCnh avatar Dec 20 '17 12:12 JoaoCnh

Also having the same issue when trying to remove form from localstorage.

bogdansoare avatar Dec 20 '17 21:12 bogdansoare

@jaredpalmer @bogdansoare I'm not really sure how this should be handled. I don't really understand why the Persist component is saving the form status after submition. Maybe using componentWillUnmount for some cleanup?

JoaoCnh avatar Dec 21 '17 14:12 JoaoCnh

When you submit the form you could try calling actions.resetForm();

Ciaran0 avatar Feb 19 '18 22:02 Ciaran0

@Ciaran0 Will try tomorrow maybe. Will report back if it works

JoaoCnh avatar Feb 23 '18 00:02 JoaoCnh

I'm also interested in this as I'm building a checkout form and don't want to persist the customer's credit card number after their transaction.

Ideally I'd rather not store the card number in localStorage at all, but haven't found a good way to avoid doing that yet. If anyone also has this use case and has found a solution, I'd love to see it.

abohannon avatar Mar 07 '19 00:03 abohannon

Yes, it would be nice to remove the form handling states from the persistence and only store the form values. I see that it uses the formik context inside, so maybe we could modify the props to provide some kind of configuration object to define which formik props to store in localstorage.

Currently i use the status.success to show the user a success screen, but this will also get persisted, so the next reload the success screen keeps displaying.

rhoffmann avatar Mar 11 '19 20:03 rhoffmann