Component LifeCycle method only being triggered for first time?
See original GitHub issueIssues
Under Tabs
component, I’ve bind only one specific component and distinguish them based on props. While tab active, this component are expect to re-render or sorts to get the relevant values. However, it seems that component lifecycle method only being executed first time for each and every tab. Meaning if we revisit the tab once again, none of component lifecycle method will being invoke.
react-native, react and native-base version
"native-base": "^2.4.2",
"react": "16.0.0",
"react-native": "0.52.0",
Expected behaviour
Component lifecycle method will be invoked everytime a tab changed.
Actual behaviour
Component lifecycle method only being invoked for first time each tab active. Component Lifecycle method will not be invoked again if the tab is revisit.
Steps to reproduce (code snippet or screenshot)
<Tabs
initialPage={this.props.day}
tabBarUnderlineStyle={{ backgroundColor: '#5AF158' }}
renderTabBar={() => <ScrollableTab />}>
{this.renderTabHeader()}
</Tabs>
renderTabHeader() {
return (
this.props.dateArray.map((date, i) =>
<Tab
key={i}
heading={date.format('DD/MM')}
tabStyle={styles.tabStyling}
activeTabStyle={styles.activeTabStyle}
textStyle={styles.tabTextStyle}
activeTextStyle={styles.activeTabTextStyle}
>
<View style={{ backgroundColor: '#EEEEEE', flex: 1 }}>
<Content contentDate={date.format('YYYY-MM-DD')} />
</View>
</Tab>
)
);
}
Content Component:
class Content extends Component {
componentWillMount() {
console.log('Component Will Mount() ?');
this.props.loadTransactionByDate({ date: this.props.contentDate });
}
componentWillUpdate(nextProps, nextState) {
console.log('Component Will Update() ?');
}
render() {
return (
<View><Text>{this.props.contentDate}</Text></View>
);
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (8 by maintainers)
Top Results From Across the Web
react native - ComponentWillMount only trigger for first time?
componentWillMount triggers only once since your component will be initial rendered/mounted only one time and that's how React works.
Read more >React lifecycle methods: An approachable tutorial with ...
Learn all about React lifecycle methods for mounting, updating, unmounting, and error handling, including new methods as of React 17.
Read more >How to understand a component's lifecycle methods in ...
There are different lifecycle methods that React provides at different phases of a component's life. React automatically calls the responsible ...
Read more >Rendering and Updating Data using Component Lifecycle ...
The componentDidMount() method will be triggered as soon as the component is mounted or inserted into the DOM. The basic syntax to use ......
Read more >React.Component
Each component has several “lifecycle methods” that you can override to run code at particular times in the process. You can use this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Somehow missed this one to check Will respond soon
I am facing this same issue right now.