PropType已定义,但从不使用prop

时间:2017-08-08 13:27:56

标签: reactjs jsx

为什么我在下面的示例代码中获取所有道具的lint错误PropType is defined but prop is never used

const propTypes = {
  prop1: PropTypes.string,
  prop2: PropTypes.string,
  prop3: PropTypes.number,
  prop4: PropTypes.string,
  prop5: PropTypes.number,
};

const userDetails = (props) => ((props.props2 > 0 & props.prop1 === props.props3) ?
  t('translation/abc')
  : t('translation/def'));

const userDetails2 = (props) => ((props.props1 > 0 & props.prop4 === props.props5) ?
  t('translation/ted')
  : t('translation/sted'));

1 个答案:

答案 0 :(得分:0)

您未将定义的propTypes对象分配给组件的实例。

将此视为一种可能的解决方案:

const propTypes = {
  prop1: PropTypes.string,
  prop2: PropTypes.string,
  prop3: PropTypes.number,
  prop4: PropTypes.string,
  prop5: PropTypes.number,
};

userDetails.propTypes = propTypes;

userDetails2.propTypes = propTypes;