【问题标题】:is missing in props validation React JS道具验证中缺少 React JS
【发布时间】:2020-03-17 09:20:24
【问题描述】:

我创建了组件:

const elementaryInfo = ({
  postTitle,
  imageUrl,
  facts,
  factSummary,
      }) => {
  return (<div> ....

我有这个错误:

postTitle, imageUrl, facts, factSummary is missing in props validation

我找到了this quetsion on this forum,但它包含像类一样创建的组件的解决方案。 我还找到了this question with answer 并在下面添加了代码:

elementaryInfo.PropTypes = {
postTitle: PropTypes.string.isRequired,
imageUrl: PropTypes.string.isRequired,
facts: PropTypes.array.isRequired,
factSummary: PropTypes.string.isRequired

但这并没有解决我的问题,我遇到了不同的错误:

Unreacheble code detected. Typo in static class property declaration.

请帮助我如何解决?

【问题讨论】:

  • propTypes 中有错字。应该是elementaryInfo.propTypes = { postTitle: PropTypes.string.isRequired, imageUrl: PropTypes.string.isRequired, facts: PropTypes.array.isRequired, factSummary: PropTypes.string.isRequired};,你从哪里得到无法访问的代码错误?
  • 无法访问的代码通常意味着您要么提前返回,要么返回语法错误,例如缺少括号、冒号、逗号等。请检查您的代码。使用该新代码,您很可能引入了某种语法错误。听起来这项工作可以用 Typescript 解决
  • 您的组件名称 `elementaryInfo` 应以大写字母开头
  • @Vishnu 是的,谢谢,我解决了,返回后添加 propTypes 时出现无法访问的代码错误
  • @EvgeniiKlepilin 谢谢你的评论你帮助了我,现在我知道了更多:)

标签: reactjs eslint


【解决方案1】:

嗨,Matz,声明应该是 elementaryInfo.propTypes

【讨论】:

    猜你喜欢
    • 2018-08-01
    • 2020-10-29
    • 2018-04-02
    • 2021-09-04
    • 2016-12-05
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    相关资源
    最近更新 更多