本文介绍了定义了PropType但从未使用prop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
const propTypes = {
prop1: PropTypes.string,
prop2: PropTypes.string,
prop3: PropTypes.number,
};
const something = (props) => ((props.props2 > 0 & props.prop1 === props.props3) ?
t('translation/abc')
: t('translation/def'));
为什么所有三个道具prop1, prop2, prop3
的组件都会抛出皮棉错误PropType is defined but prop is never used
?
why does the component throw lint error PropType is defined but prop is never used
for all three props prop1, prop2, prop3
?
推荐答案
这应该可以解决您的问题,让我们分解道具的结构,然后将propTypes分配给无状态组件.
This should fix your problem, let's de-structure your props and then assign propTypes to your stateless component.
const something = ({prop1, prop2, prop3}) => ((props2 > 0 & prop1 === props3)
? t('translation/abc')
: t('translation/def'));
something.propTypes = {
prop1: PropTypes.string,
prop2: PropTypes.string,
prop3: PropTypes.number,
};
这篇关于定义了PropType但从未使用prop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!