程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用 reactstrap 从 react-hook-form 访问错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决使用 reactstrap 从 react-hook-form 访问错误?

开发过程中遇到使用 reactstrap 从 react-hook-form 访问错误的问题如何解决?下面主要结合日常开发的经验,给出你关于使用 reactstrap 从 react-hook-form 访问错误的解决方法建议,希望对你解决使用 reactstrap 从 react-hook-form 访问错误有所启发或帮助;

我用 reactstrap 和 react-hook-form 创建了一个表单。为什么我的错误没有显示?

呈现文本输入的虚拟部分:

@H_@R_696_11277@_8@function DummySection() { const { control } = useForm(); return ( <div> <Controller name="dummyname" control={Control} rules={{ required: true }} DefaultValue="" render={({ fIEld: { onChange,ref },fIEldState: { error } }) => ( <TexTinput onChange={onChangE} innerRef={ref} error={error} /> )} /> </div> ); }

文本输入错误:

@H_@R_696_11277@_8@function TexTinput({ onChange,value,innerRef,error }) { const updateText = (E) => { onChange(E); // do something else below }; return ( <div> <input name="dummyname" type="text" onChange={(E) => updateText(E)} value={@R_772_6084@ innerRef={innerRef} /> {error && "CAnnot be blank"} </div> ); }

提交按钮

@H_@R_696_11277@_8@function submitBtn() { const { handlesubmit } = useForm(); const onsubmit = (data) => console.log(data); return <button onClick={() => handlesubmit(onsubmit)()}>submit</button>; }

谢谢。

Code Sandbox

解决方法

@jamfie,您为每个组件使用了不同的 useForm

您的表单需要具有相同的实例,您可以通过使用 useformcontext 或将 props 传递给组件来实现。

另外,你不需要控制器来做这件事, 这里的 codesandbox 展示了如何将 reactstrap 与 react-hook-form 结合使用。

您也可以在 github issue 中关注 this answer。

大佬总结

以上是大佬教程为你收集整理的使用 reactstrap 从 react-hook-form 访问错误全部内容,希望文章能够帮你解决使用 reactstrap 从 react-hook-form 访问错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。