简体   繁体   English

Eslint - 道具验证中没有'匹配'(反应/道具类型)

[英]Eslint - 'match' is missing in props validation (react/prop-types)

My eslint is failing on the following line. 我的意志在下一行失败了。

  const id = this.props.match.params.personID;

How can I fix this. 我怎样才能解决这个问题。 Setting a rule to ignore would be ok. 将规则设置为忽略即可。 Finding a fix would be better. 找到一个解决方案会更好。

Error 错误

 severity: 'Error'
    message: ''match' is missing in props validation (react/prop-types)'
    at: '14,27'
    source: 'eslint'
    code: 'react/prop-types'

When you are checking your prop types you also have to verify the shape of match. 当您检查您的道具类型时,您还必须验证匹配的形状。

If you are using flow: 如果您正在使用流程:

type Props = {
  match: {
    params: {
      field1: number,
      field2: string,
    }
  }
  ...
}

class Component extends React.Component<Props> {
  ...
}

If you aren't and are using PropTypes ... 如果您不是并且正在使用PropTypes ...

import PropTypes from 'prop-types';

class MyComponent extends React.Component {
  ...
}

MyComponent.propTypes = {
  match: PropTypes.shape({
    params: PropTypes.shape({
      field1: PropTypes.number.isRequired
      field2: PropTypes.string
    })
  }),
  ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM