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

fix: add a cleanup function to useEffect that loads data from storage. #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mkhennoussi
Copy link

@mkhennoussi mkhennoussi commented Oct 4, 2022

Hi !

This fixes the issue with data not loaded from the storage as the Effects are fired twice in dev: https://beta.reactjs.org/learn/synchronizing-with-effects#how-to-handle-the-effect-firing-twice-in-development

It simply creates a cleanup function that wirte to the storage after reading it.

Should fix: #18

Hope it helps !

@BorjaRafolsMartinez
Copy link

This actually makes this plugin work with defaultValues option from react-hook-form

@Alain1405
Copy link

I can confirm with this fix the form values are persisted even when defaultValuea is passed to useForm. Without this defaultValues overrides the persisted state.
An alternative solution would be to pass defaultValues directly to useFormPersist

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

Successfully merging this pull request may close these issues.

Doesn't seem to work on refresh
3 participants