React-navigation, tintColor is missing in props validation

允我心安 提交于 2020-05-15 04:15:28

问题


I have put my react-navigation code into a separate Routes file which I am then importing into my App.js file. Everything is working fine but I am using Airbnb ESLint config in Atom/Nuclide and getting an error with tintColor...

"tintColor is missing in props validation"

Tried this:

Routes.propTypes = { tintColor: PropTypes.string.isRequired,}

But then get error "tintColor PropType is defined but prop is never used"

This is part of the code

const Routes = () = {
const ContentNavigator = TabNavigator(
{
  Profile: { screen: ProfileStack },
  History: { screen: HistoryStack },
  Questions: {
    screen: QuestionsStack,
    navigationOptions: {
      tabBarIcon: ({ tintColor }) => (
        <Icon name="question-circle" type="font-awesome" size={20} color=
 {tintColor} />
      ),
    },
  },
  Notifications: { screen: NotificationsStack },
},
{
  initialRouteName: 'Profile',
  swipeEnabled: true,
  tabBarOptions: {
    activeTintColor: COLOR_PRIMARY,
  },
  backBehavior: 'none',
});

回答1:


You could create an additional Functional Component, add PropTypes for it and use in your main component. For example:

...
import PropTypes from 'prop-types';
...

const QuestionsTabBarIcon = ({ tintColor }) => (
  <Icon name="question-circle" type="font-awesome" size={20} color={tintColor} />
);
QuestionsTabBarIcon.propTypes = {
  tintColor: PropTypes.string.isRequired,
};

...

const ContentNavigator = TabNavigator(
  {
    Profile: { screen: ProfileStack },
    History: { screen: HistoryStack },
    Questions: {
      screen: QuestionsStack,
      navigationOptions: {
        tabBarIcon: QuestionsTabBarIcon
      },
    },
    Notifications: { screen: NotificationsStack },
  },
  {
    initialRouteName: 'Profile',
    swipeEnabled: true,
    tabBarOptions: {
      activeTintColor: COLOR_PRIMARY,
    },
    backBehavior: 'none',
  }
);

...


来源:https://stackoverflow.com/questions/46396202/react-navigation-tintcolor-is-missing-in-props-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!