javascript - TypeError : props. render is not a function (React hook form)

标签 javascript reactjs

我以我用 react-hook-form 制作的这种形式将方法作为 Prop 传递。
当从 react-hook-form 添加 Controller 时,它给了我(TypeError:props.render 不是函数)。我在网上找不到任何解决方案,因此不胜感激。

import { useForm, FormProvider } from 'react-hook-form';
import FormInput from './CustomTextField';

const AddressForm = () => {
  const methods = useForm();

  return (
    <>
      
      <FormProvider {...methods}>
        <form onSubmit=' '>
          <Grid container spacing={3}>
            <FormInput required name='firstName' label='First name' />
          </Grid>
        </form>
      </FormProvider>
    </>
  );
};



import { useFormContext, Controller } from 'react-hook-form';


const FormInput = ({ name, label, required }) => {
  const { control } = useFormContext();
  

  return (
    <>
      <Controller
        as={TextField}
        name={name}
        control={control}
        label={label}
        fullWidth
        required={required}
        
      />
    <>
  );
};

export default FormInput;

最佳答案

陷入了类似的问题,
您可以尝试在 中进行以下更改表单输入 功能:

import React from 'react';
import { TextField, Grid } from '@material-ui/core';
import { useFormContext, Controller } from 'react-hook-form';


const FormInput = ({ name, label, required}) => {
const { control } = useFormContext();
   const isError = false;

return (
   <>
         <Controller
            control={control}
            name={name}
            render = {({ field})=> (
                <TextField
                    fullWidth
                    label={label}
                    required
                />
            )}
         />
   </>
 );
 }

export default FormInput;
希望这有帮助,否则你可以通过 docs

关于javascript - TypeError : props. render is not a function (React hook form),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66957809/

相关文章:

javascript - React 中与子组件的交叉观察器

javascript - 计算特定长度的数据列中的事件数

javascript - 有没有办法在没有显示有效输入时显示消息?

javascript - jquery在元素之间多次插入html

javascript - 如何在React中动态加载脚本

reactjs - 错误 : Actions must be plain objects. 相反,实际类型为 : 'function' . 您可能需要将中间件添加到您的商店设置中

javascript - 有没有办法控制弹出器中嵌套的 Material UI 选择在 DOM 中的安装位置?

css - 如何禁用 Material-UI 的 "Select"组件中的某些选项,例如 "Autocomplete"?

javascript - 拖动图像时底层对象上的 jQuery 鼠标事件

javascript - <select> 中 HTML <option> 中的样式子字符串