Skip to content
Discussion options

You must be logged in to vote

Only providing defaultValue won't change isDirty because a comparison between defaultValue and current formValues will be made.
To update the formValues at first, you must use setValue or reset.

  const {
    reset,
  } = useForm({
    defaultValues: {
      firstName: "",  // The value shouldn't be `test`. defaultValues can be omitted. 
    },
    mode: "onChange",
  });
  
  useEffect(() => {
    reset(
      {
        firstName: "test",
      },
      { keepDefaultValues: true }
    );
  }, [reset]);

Here is the codesandbox.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@keanan
Comment options

@sujinleeme
Comment options

@keanan
Comment options

@sujinleeme
Comment options

Answer selected by keanan
@keanan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants