Next.js Discord

Discord Forum

react hook form

Unanswered
Maltese posted this in #help-forum
Open in Discord
MalteseOP
Hello! I am using React Hook Form, does somebody know how to abort the defaultValues function if the field is dirty, because now when u type something and after 5 seconds the fields get reset to default value state
this is my function
const { register, handleSubmit, formState, watch } = useForm<TFormShema>({
    defaultValues: async () => {
      const name = await getName();

      return {
        username: name,
        password: 'asd',
        socials: {
          facebook: '',
          twiter: '',
        },
      };
    },
  });

async function getName(): Promise<string> {
  await wait(5000);
  const resp = await fetch('https://jsonplaceholder.typicode.com/users/1');
  const obj: Person = await resp.json();
  return obj.name;
}

0 Replies