KendoReact and react-hook-form

问题描述 投票:1回答:1

[在使用KendoReact库的react-hook-form组件时遇到麻烦:

<Controller
   as={Input}
   name="firstName"
   control={control}
   defaultValue="type something here"
/>

Stackblitz sample here

react-hook-form sample正在使用MaterialUI组件显示第三方库集成,并且似乎工作正常。使用Kendo输入组件时,在输入控件中键入任何内容都会导致控件显示[object Object]而不是键入的值。这是因为要在控件上设置的值是event对象,而不是实际值。

我找不到解决此问题的方法,希望其他人确实找到了解决方法。

reactjs react-hook-form kendo-react-ui
1个回答
1
投票

在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"
  />

stackblitz

© www.soinside.com 2019 - 2024. All rights reserved.