【问题标题】:Line 18:19: 'value' is missing in props validation第 18:19 行:道具验证中缺少 \'value\'
【发布时间】: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


【解决方案1】:

也许问题可能是第 7 行中的 2 个括号?

if (value === "true"){
return <Employee />
}else{
return <Employer />
}

【讨论】:

    猜你喜欢
    • 2021-09-04
    • 2018-06-14
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-26
    相关资源
    最近更新 更多