Skip to content

Calling conditionally? #30

Open
Open
@brandondurham

Description

@brandondurham

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions