React Functions Lifecycle

When moving away to from class components in React (simpler syntax and enables the use of hooks) you sometimes need to attach some code according to the lifecycle of the component. The code below is an example of this. import React from 'react' const Home = (props) => { React.useEffect(() => { console.log('Component has mounted'); return () => { console.log('Component is unmounting'); }; }, []); React.useEffect(() => { console.log('Component updated'); }); return ( <div> <h3>Home</h3> </div> ); } export default Home ...

May 2, 2021