简体   繁体   中英

react-hook-form doesn't render MUI RadioGroup with selected option when going back to previous step

I am trying to implement a multi-step form with react-hook-form(v6) using FormProvider and useFormContext API. I am using MUI(V5) as UI Component Library. When I go forward by click Next button form works fine. but when going back, previous step doesn't render MUI Radio with selected option.

I have created a sandbox to demonstrate what i am doing exactly - https://codesandbox.io/s/eager-tdd-hyye9z

In react-hook-form v6 i had to pass shouldUnregister: false in useForm options.

  const methods = useForm({
    mode: "all",
    reValidateMode: "onChange",
    defaultValues: {},
    shouldUnregister: false
  });

There is working example https://codesandbox.io/s/naughty-hodgkin-d7u4ee

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM