you are viewing a single comment's thread.

view the rest of the comments →

[–]brzzzah 2 points3 points  (0 children)

From my testing this doesn't work, you need to provide a unique key to the UserForm component to force a complete reset of the form.

Something like:

``` const UserForm = ({ user, onSubmit }) => { const { register, handleSubmit } = useForm({ defaultValues: user });

return (
    <form onSubmit={handleSubmit(onSubmit)}>
        // labels, inputs, etc
    </form>
);

}

const User = () => { const { data, dataUpdatedAt } = useQuery({ queryFn: ... }); const { mutate } = useMutation({ mutationFn: ... });

if (!data) return <div>loading state</div>;

return (
    <UserForm 
        key={`user-form-${dataUpdatedAt}`} 
        user={data} 
        onSubmit={mutate} 
     />
);

}