tiaanduplessis / react-hook-form-persist

Persist and populate react-hook-form form using storage of your choice
MIT License
168 stars 23 forks source link

feat: bail if name is null #31

Closed brandondurham closed 1 year ago

brandondurham commented 2 years ago

Added check (with test) to ensure name is set. If not, return. This would allow for setting up useFormPersist conditionally with a prop:

const MyComponent = ({ persistKey }) => {
    const { watch, setValue } = useForm();

    useFormPersist(persistKey, {
        setValue,
        watch,
    });

    return (
        <form>
            ...
        </form>
    );
};

Using MyComponent without useFormPersist:

<MyComponent persistKey={null} />`

Fixes #30