eslint - 我如何通过 eslint 检查 this.props.navigation.navigate (react-navigation)?

标签 eslint react-navigation react-proptypes

我在我的 native 项目中使用 eslint airbnb。如果我没有验证 Prop ,特别是来自 react-navigation 的 Prop ,eslint 会抛出错误 linting .

props validation 1
我如何使用 PropTypes 验证这一点?

我正在尝试像这样验证它:

IntroScreen.propTypes = {
  navigation: PropTypes.shape({
    navigate: PropTypes.func,
  }),
};

但仍然有这样的错误 linting
error lint 2

我如何传递默认 Prop ,我应该吗?

最佳答案

我正在通过设置导航和导航 Prop 来修复它。

IntroScreen.propTypes = {
  navigation: PropTypes.shape({
    navigate: PropTypes.func.isRequired,
  }).isRequired,
};

如果我们将 Prop 设置为可选,eslint 会强制我们提供要设置的默认 Prop 。因此,如果我们将 props 设置为必需,eslint 将不会再次警告您。

关于eslint - 我如何通过 eslint 检查 this.props.navigation.navigate (react-navigation)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46578927/

相关文章:

vue.js - “v-slot”指令不支持任何修饰符

html - 在恼人的 vue 的 html 格式上禁用 eslint-prettier

react-native - 如何加载具有不同参数的相同屏幕?

javascript - React Native - PropTypes.bool 中的 "Cannot read property ' bool' 未定义

javascript - 'prop-types' 应该列在项目的依赖项中,而不是 devDependencies

chai - 使用 chai 消除 no-unused-expressions linter 错误的好方法

react-native - 如何使用 ReactNavigation 判断 View 何时出现

react-navigation - 在 IOS 中使用 react 导航的空白屏幕

reactjs - PropTypes.exact 和 PropTypes.shape 之间的区别

reactjs - 无法加载在 '@typescript-eslint' : Class extends value undefined is not a constructor or null 中声明的插件 '.eslintrc'