阵营导航“导航”中的道具验证缺少
问题描述:
阵营导航的introduction page建议使用以下解构赋值的:阵营导航“导航”中的道具验证缺少
const { navigate } = this.props.navigation;
然而,当我实现我的应用程序阵营导航,ESLint抱怨这条线描述这些既错误:
“导航”在道具验证缺失(反应/丙类型)
“navigation.navigation”在缺少道具验证(反应/道具类型)
即使应用程序似乎按预期工作,如何才能删除这些错误行?
答
一个选项是将propTypes
prop添加到组件。
例
LoginScreen.propTypes = {
navigation: PropTypes.object.isRequired,
};
另一种选择是禁用eslint该页面和规则。更多信息here
规则选项
这个规则可以采取一个参数期间 验证忽略某些特定的道具。
... "react/prop-types": [<enabled>, { ignore: <ignore>, customValidators: <customValidator> }] ...
答
解决方案今日(因为对象Proptype默认情况下不接受的了):
export default class LoginScreen extends Component {
static propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func.isRequired,
}).isRequired,
}
}
最新版本现在抱怨的对象类型: 'Eslint:支柱型 '对象' 是被禁止的反应/禁止 - 丙types' – mcabe