【问题标题】:Why onChange of react-form-hooks not working in react native?为什么 react-form-hooks 的 onChange 在本机反应中不起作用?
【发布时间】:2021-06-11 09:43:57
【问题描述】:

//下面的代码给出了一个错误:'onChange is not a function'。 我渲染 TextInput 并且它是动态的,这意味着我正在使用 react-hook-form 创建动态表单,但 onChange 不起作用。请帮助!

   <Controller
    control={control}
    name={fields.field_name[index]}
    rules={{ required: true }}
    render={({ onChange, value }) => (
        <TextInput
            placeholder={' ' + fieldName}
            editable={fields.context_type == 'Location' ? false : true}
            keyboardType={fields.context_type == 'Decimal' ? 'decimal-pad' : 'default'}
            value={fields.context_type == 'Location' ? machineLocation : value}
            onChangeText={(value) => onChange(value)}
        ></TextInput>

    )}
/>

【问题讨论】:

  • Controller 是什么?
  • 我认为你需要 field: { onChange } 作为你的渲染道具

标签: javascript reactjs react-native react-hooks


【解决方案1】:

你需要调用渲染函数为

render = {(fields:{onChange,value}) => {
}

在最新版本的 react-hook 表单中实现了此更改

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    相关资源
    最近更新 更多