I'm using native-base
, redux
and react-native
, It seems that switching between tabs doesn't call the method componentWillUnmount
, I want to do some actions when the tab is switched and the component is removed:
Main.js
export class Main extends Component {
render() {
return (
<Container style={styles.containerStyle}>
<Tabs initialPage={0} >
<Tab heading="Tab1">
<Tab1 />
</Tab>
<Tab heading="Tab2">
<Tab2 />
</Tab>
</Tabs>
</Container>
)
}
}
Tab1.js
export class Tab1 extends Component {
constructor(props) {
super(props);
}
componentWillMount(){
//called
}
componentWillUnmount(){
//not called when switching tabs
}
render() {
return (
<Container style={styles.containerStyle}>
<Content>
<Text>Tab1</Text>
</Content>
</Container>
);
}
}
How to call actions when the tab is switched and the component is removed?