Skip to content

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

Open
mkhennoussi wants to merge 1 commit into
tiaanduplessis:masterfrom
mkhennoussi:fix-effects-firing-twice
Open

fix: add a cleanup function to useEffect that loads data from storage.#29
mkhennoussi wants to merge 1 commit into
tiaanduplessis:masterfrom
mkhennoussi:fix-effects-firing-twice

Conversation

@mkhennoussi
Copy link
Copy Markdown

@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
Copy Markdown

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

@Alain1405
Copy link
Copy Markdown

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