React useEffect hook lifecycle

React
  • Mount
  • Update
  • Unmount

Prerequisites

import { useEffect } from 'react';

Mount

useEffect(() => {
console.log('mount');
}, []);

Update

useEffect(() => {
console.log('update');
});
useEffect(() => {
console.log('update on data change');
}, [data]);
useEffect(() => {
return () => {
console.log('update on data change or unmount');
};
}, [data]);

Unmount

useEffect(() => {
return () => {
console.log('unmount');
};
}, []);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store