Component Life Cycle in React Native
https://reactjs.org/docs/react-component.html Click here to read the documentation.
There are 3 types of Lifecycle methods available in React Native.
- Mounting methods
- constructor()
- getDerivedStateFromProps()
- render()
- componentDidMount()
2. Updating methods
- shouldComponentUpdate()
- componentWillUpdate()
- componentDidUpdate()
3. Unmounting methods
- componentWillUnmount()
Mounting
Mounting is an instance of a component is being created and inserted into the DOM.
These methods are called in the following order when an instance of a component is being created and inserted into the DOM:
- constructor()
- static getDerivedStateFromProps()
- render()
- componentDidMount()
Updating
Updating methods are used to update the value of Props or State to React Native. These methods are called automatically when a component re-renders.
An update can be caused by changes to props or state. These methods are called in the following order when a component is being re-rendered:
- static getDerivedStateFromProps()
- shouldComponentUpdate()
- render()
- getSnapshotBeforeUpdate()
- componentDidUpdate()
UnMounting
This method is called when a component is being removed from the DOM:
- componentWillUnmount()
It is called when the component is removed from the DOM, Users can clear any running timers, stop network requests and cleaning any previously stored value in the application in this method.
I hope you enjoyed this article. See you again with more articles. If you liked this post, don’t forget to share it with your network.