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>
)
}