我已将反应导航代码放入单独的Routes文件中,然后将其导入到我的App.js文件中。一切正常,但我在Atom / Nuclide中使用Airbnb ESLint配置并使用tintColor获取错误......
道具验证中缺少" tintColor"
试过这个:
Routes.propTypes = {tintColor:PropTypes.string.isRequired,}
然后得到错误" tintColor PropType已定义,但道具从未使用"
这是代码的一部分
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',
});
答案 0 :(得分:3)
您可以创建一个额外的Functional Component,为其添加PropTypes
并在主要组件中使用。例如:
...
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',
}
);
...