reactjs - KendoReact 和 react-hook-form
问题描述
我在使用带有react-hook-form库的KendoReact组件时遇到问题:
<Controller
as={Input}
name="firstName"
control={control}
defaultValue="type something here"
/>
react-hook-form示例使用 MaterialUI 组件来显示第三方库的集成,并且看起来工作正常。使用 Kendo Input 组件时,在输入控件中键入任何内容都会导致控件显示[object Object]
而不是键入的值。这是因为要在控件上设置的值是event
对象而不是实际值。
我找不到解决方法,希望其他人确实找到了。
解决方案
在 Input 周围创建一个简单的包装器以从中获取值onChange
将起作用:
const InputWrapper = props => {
return <Input {...props} onChange={e => {
props.onChange(e.target.value)
}} />
}
...
<Controller
as={InputWrapper}
name="firstName"
control={control}
defaultValue="type something here"
/>
推荐阅读
- reactjs - 使用 Webpack 4 加载较少语法的问题
- java - 从 X 到扩展 X 的泛型类型的未经检查的强制转换
- javascript - 用所需的图像替换 Font Awesome 图标
- css - 根据移动 Web 应用的屏幕尺寸构建自动调整元素大小是否是一种好习惯?
- ios - 在出现在 iOS 之前添加按钮渐变
- python - 使用 for 循环将字符串附加到列表中,其中附加的每个项目都是一个新字符串
- arduino - 如何从串行监视器读取字符数组并相应地命令arduino?
- c++ - 如何为项目本身、构建产品和源文件创建一个具有不同位置的简单 CLion C++ CMake 项目
- datatables - 确认抽奖已完成
- python - TensorFlow中应该如何实现欧拉积分?