我有以下代碼:reactJs警告:的setState(...):只能更新一安裝或安裝組件
class MainScreen extends Component {
constructor(props) {
super(props);
this.state = {
selectedTab: 'news'
};
}
componentWillMount() {
this.props.dispatch({
type:'isLoggedIn',
isLoggedIn: false
})
}
shouldComponentUpdate() {
console.log('shouldComponentUpdate: --------')
return false;
}
navigateToAuthScreen() {
this.props.navigator.immediatelyResetRouteStack([
rootRoutes.authScreen
]);
}
componentWillReceiveProps(nextProps) {
console.log('componentWillReceiveProps: ----');
if (!nextProps.isLoggedIn) this.navigateToAuthScreen();
}
render() {
console.log('rending: ----------------------');
return (
<View style={styles.container}>
<TabBarIOS tintColor={theme.accentColor} translucent>
<Icon.TabBarItem
iconName="newspaper-o"
title="News"
selected={this.state.selectedTab === 'news'}>
<SceneStack
initialRoute={newsRoutes.newsListing}
/>
</Icon.TabBarItem>
</TabBarIOS>
</View>
);
}
}
更新:
我發現這個錯誤有什麼以某種方式處理TabBarIOS和Icon.TabBarItem。
我已經完全刪除onPress={() => this.switchTabsOrPopStack('news')}
和錯誤還是發生了。
我收到此錯誤:
警告:的setState(...):只能更新一安裝或安裝組件。這通常意味着您在卸載的組件上調用了setState()。這是一個沒有操作。請檢查TabBarItem組件的代碼。
我不知道我錯過了什麼。
因爲導航器,我陷入了相同的情況,你可以詳細說明如何解決這個問題。 –