我尝试使用 react-hook-form 来验证输入。但是我发现如果输入放在 Material UI 的对话框组件中,react-hook-form 的setValue没有按预期工作,但是当我删除 Dialog 组件时它可以工作。我猜原因是在组件挂载之前设置了值,但仍然找不到解决方案。 该值将从服务器检索,所以我不能使用 react-hook-form
import { useForm } from "react-hook-form"; const App = () => { const { register, setValue } = useForm(); return ( <form> <input {...register("firstName")} /> <button type="button" onClick={() => setValue("firstName", "Bill")}> setValue </button> <button type="butto...
import { useForm } from "react-hook-form" const App = () => { const { register, setValue } = useForm({ firstName: "", }) return ( <form> <input {...register("firstName", { required: true })} /> <button onClick={() => setValue("firstName", "Bill")}>setValue</butto...
HTML inputs are stateful, they don't need to be driven by external state/props and that's what react hook form is great for. I can easily introduce the 4th argument, but I don't feel it's the right thing to do.
Sign in Sign up react-hook-form / react-hook-form Public Sponsor Notifications Fork 2.1k Star 42.1k Code Issues 21 Pull requests 42 Discussions Actions Projects 1 Security Insights New issue issue: setValue triggers rerender of components that shouldn't be rerendered #1...
如果使用Hook的inital setValue方法,React不会更新值 、 我创建了一个functional component,并尝试如果一个useState钩子的旧setValue方法更新钩子维护的值。因此,我创建了一个包含所有listOfSetValueMethods方法的数组setValue。在myButtonClick()方法中,我使用了first setValue方法来更新钩子的值:不工作,:react没有重新...
reactjs 在MUI Stepper-Dialog setValue内的react-hook-form控制器内ReactMUI文本字段不起作用工作CSB -...
Go to 'https://codesandbox.io/s/react-hook-form-set-inputselect-value-21zkn?file=/src/index.js' Click on 'set All Values' only watch label changed value, useWatch didn't change I see the problem because you are using setValue with a nested object.useWatchis based on inputnameand that...
updateFormState]=React.useState(control._formState);const_localProxyFormState=React.useRef({isDirty:false,isLoading:false,dirtyFields:false,touchedFields:false,validatingFields:false,isValidating:false,isValid:false,errors:false,});// ...returngetProxyFormState(formState,control,_localProxyFormState....