Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React-不能用作JSX组件。其返回类型“void”不是有效的JSX元素_Reactjs - Fatal编程技术网

Reactjs React-不能用作JSX组件。其返回类型“void”不是有效的JSX元素

Reactjs React-不能用作JSX组件。其返回类型“void”不是有效的JSX元素,reactjs,Reactjs,我有一个 这是一个超级简单的应用程序,应该只显示下面带有测试的输入和输入字段中输入内容的输出 我在输入组件上得到一个错误 'CustomInput' cannot be used as a JSX component. Its return type 'void' is not a valid JSX element. 有人知道我为什么会出现此错误吗您需要在返回后添加括号: const CustomInput = ({children, value, onChange}: CustomIn

我有一个

这是一个超级简单的应用程序,应该只显示下面带有测试的输入和输入字段中输入内容的输出

我在输入组件上得到一个错误

'CustomInput' cannot be used as a JSX component.
  Its return type 'void' is not a valid JSX element.

有人知道我为什么会出现此错误吗

您需要在返回后添加括号:

const CustomInput = ({children, value, onChange}: CustomInputProps) => {
  return (
    <div>
      <label htmlFor="search">{children}</label>
      <input id="search" type="text" value={value} onChange={onChange} />
    </div>
  )
}

您需要在返回后添加括号:

const CustomInput = ({children, value, onChange}: CustomInputProps) => {
  return (
    <div>
      <label htmlFor="search">{children}</label>
      <input id="search" type="text" value={value} onChange={onChange} />
    </div>
  )
}

定义道具类型的更好方法是:

const CustomInput:React.FC<CustomInputProps> = ({children, value, onChange}) => {
  return  (
    <div>
      <label htmlFor="search">{children}</label>
      <input id="search" type="text" value={value} onChange={onChange} />
    </div>
  )
}

定义道具类型的更好方法是:

const CustomInput:React.FC<CustomInputProps> = ({children, value, onChange}) => {
  return  (
    <div>
      <label htmlFor="search">{children}</label>
      <input id="search" type="text" value={value} onChange={onChange} />
    </div>
  )
}

代码应该是有问题的,支持非现场版本。然而,场外代码似乎并没有复制您的问题。。你链接了正确的示例吗?抱歉,我现在用正确的链接更新了它。代码应该在问题中,支持非现场版本。然而,场外代码似乎并没有复制您的问题。。你链接了正确的例子吗?对不起,我现在用正确的链接更新了它
const CustomInput:React.FC<CustomInputProps> = ({children, value, onChange}) => {
  return  (
    <div>
      <label htmlFor="search">{children}</label>
      <input id="search" type="text" value={value} onChange={onChange} />
    </div>
  )
}