【发布时间】:2022-08-18 00:31:10
【问题描述】:
我有这个注册页面,它一直向我显示这个错误 \"Line 18:19:\'value\' is missing in props validation\":
const Register = () =>{
const [value, setMyValue] = useState()
此函数根据用户在 select 标签中的选择显示一个组件
const Choice = ({ value }) =>{
if (value === \"true\"){
return <Employee />
}else{
return <Employer />
}
}
return(
<div>
<Navbar />
<div className=\"container-xxl bg-primary page-header\">
<div className=\"container text-center\">
<h1 className=\"text-white animated zoomIn\">Sign Up</h1>
<nav aria-label=\"breadcrumb\">
</nav>
</div>
</div>
<div className=\"container-xxl py-5\" id=\"contact\">
<div className=\"container\">
<div className=\"mx-auto text-center wow fadeInUp\" data-wow-delay=\"0.1s\" style=
{{maxWidth: 600}}>
<div className=\"d-inline-block border rounded-pill text-primary px-4 mb-2\">Sign Up
As</div>
<select onChange={(e)=>{setMyValue(e.target.value)}} className=\"form-select\" aria-
label=\"Default select example\">
<option value=\"false\">Employer</option>
<option value=\"true\">Employee</option>
</select>
<h2 className=\"mb-5 mt-4\">Sign Up to find the best employees</h2>
</div>
<div>
<Choice value={ value } />
</div>
</div>
</div>
</div>
)
}
顺便说一下,这是第 18 行:
const Choice = ({ value }) =>{
-
您是否从
Register组件中传递了Choice组件中的value属性? -
是的,在代码中你会看到它,是不是像这样的<Choice value={value} />?
-
是的,我看到了,但那是在
Choice里面 -
你能分享
Register的完整代码吗? -
这是来自 ESLint 的 react/prop-types 吗?你定义了你的 propTypes 吗?
标签: reactjs