Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting localStorage entry #5

Open
JoaoCnh opened this issue Dec 20, 2017 · 6 comments
Open

Deleting localStorage entry #5

JoaoCnh opened this issue Dec 20, 2017 · 6 comments

Comments

@JoaoCnh
Copy link

JoaoCnh commented Dec 20, 2017

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 component rendering it wouldn't submit more entries to localStorage

@bogdansoare
Copy link

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

@JoaoCnh
Copy link
Author

JoaoCnh commented Dec 21, 2017

@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?

@Ciaran0
Copy link

Ciaran0 commented Feb 19, 2018

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

@JoaoCnh
Copy link
Author

JoaoCnh commented Feb 23, 2018

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

@abohannon
Copy link

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.

@rhoffmann
Copy link

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.

benzaita added a commit to benzaita/formik-persist that referenced this issue Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants