In this article we will use some methods to maintain react lifecycle in functional and class component.
React LifeCycle in Functional and Class Component For the stable version of hooks (React Version 16.8.0+)
componentDidMount in Class Component for same we can use useEffect as below in Functional Component
useEffect(() => {
// Your code here
}, []);
componentDidUpdate in Class Component for same we can use useEffect as below in Functional Component
useEffect(() => {
// Your code here
}, [yourDependency]);
componentWillUnmount in Class Component for same we can use useEffect as below in Functional Component
useEffect(() => {
// componentWillUnmount
return () => {
// Your code here
}
}, [yourDependency]);
Recommendation
How to validate form in ReactJS
How to create charts in ReactJS
Call Child Functions in React Parent
How to call methods on browser resize in React
How to detect click outside of component in React
For more ReactJS Tutorials Click here.
If you like this, share this.