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

Calling conditionally? #30

Open
brandondurham opened this issue Oct 24, 2022 · 0 comments
Open

Calling conditionally? #30

brandondurham opened this issue Oct 24, 2022 · 0 comments

Comments

@brandondurham
Copy link

brandondurham commented Oct 24, 2022

I was looking at incorporating into an existing FormWizard component that uses RHF and is used in many places across our application. I’ve added a persistKey prop (string) that, when present, would just be used to enable form persist within that instance of the wizard. Like this:

if (persistKey && typeof persistKey === 'string') {
	useFormPersist(persistKey, {
		setValue,
		watch,
	});
}

However, it’s not recommended to conditionally apply hooks in a component, so what would be the recommended process here?

I was considering forking the project and adding something like this to the two useEffect blocks:

if (!name) return

Thoughts?

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 a pull request may close this issue.

1 participant