【发布时间】:2019-05-11 18:34:27
【问题描述】:
我在我的 React Native 项目中使用 Eslint,在这段代码中:
export default class AuthLoadingScreen extends React.Component {
constructor() {
super();
this.bootstrapAsync();
}
bootstrapAsync = async () => {
const userToken = await AsyncStorage.getItem('userToken');
this.props.navigation.navigate(userToken ? 'App' : 'Auth');
};
render() {
return (
<View style={styles.container}>
<ActivityIndicator />
<StatusBar barStyle="default" />
</View>
);
}
}
Eslint 给出警告:“必须使用解构道具分配”。我试图将分配更改为
const navigation = this.props;
navigation.navigate(userToken ? 'App' : 'Auth');
但它给出了一个错误:“未定义不是一个对象”
编辑: 将构造函数更改为:
constructor(props) {
super(props);
this.bootstrapAsync(props);
}
现在代码运行没有错误
【问题讨论】:
标签: javascript react-native eslint