问题
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