A lot of frontends are legacy and mainly composed of class components, hence why it’s still very useful practically, even though it is not the preferred method any longer. Answer from Deleted User on reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › reactjs-lifecycle-components
React Lifecycle - GeeksforGeeks
It provides a structured way to handle specific tasks at various points in a component’s life, such as when it is created, updated, or destroyed. Data Fetching: Lifecycle methods let you fetch data and update external resources at the right time. Performance Optimization: Prevents unnecessary re-renders to improve performance. Resource Management: Cleans up listeners, requests, and timers to prevent memory leaks. State & Props Handling: Lifecycle hooks manage state or props changes smoothly.
Published   3 weeks ago
🌐
W3Schools
w3schools.com › react › react_lifecycle.asp
React Lifecycle
React useState React useEffect React useContext React useRef React useReducer React useCallback React useMemo React Custom Hooks ... React Compiler React Quiz React Exercises React Syllabus React Study Plan React Server React Interview Prep React Bootcamp ... Each component in React has a lifecycle which you can monitor and manipulate during its three main phases.
Discussions

Does "thinking in lifecycle" still a thing given that we all use functional components nowadays?
A lot of frontends are legacy and mainly composed of class components, hence why it’s still very useful practically, even though it is not the preferred method any longer. More on reddit.com
🌐 r/reactjs
39
79
April 14, 2023
How to use lifecycle methods with hooks in React?
I have gone through hooks introduced in react v16.7.0. https://reactjs.org/docs/hooks-intro.html So my understanding about hooks is we can play with state in functional component without writing... More on stackoverflow.com
🌐 stackoverflow.com
Am i the only one who finds React lifecycle hooks super confusing?
useEffect() notifies you when something changes. useEffect(() => { // execute this code }, [ // when those dependencies change ]) Using an empty array means there are no dependencies, so the code runs only on mount and unmount of the component. useEffect(() => { // this runs on mount return () => { // this runs on unmount } }, []) You can use it to monitor change and trigger an effect. const [user, setUser] = useState(null) useEffect(() => { // this runs when the user gets re-assigned }, [user]) If you want to fetch some data when mounting a component, do it like this: const [post, setPost] = useState(null) useEffect(() => { axios.get('http://dummyapi.com/posts/123').then(response => setPost(response)) }, []) This will run on mount, execute a call and store the results in your internal state. You can then display those results. The whole topic is a little more complex when you want to be correct with the exhaustive-deps lint, but this should be enough to start with. ETA: Thanks for the awards and love! I know a lot of information is missing in this comment and there are some unhandled possible difficulties, there is always way to improve and make your code better! This is just a "getting started" guide and I encourage you to study more about useEffect and also useCallback and most importantly - code your projects and watch your console logs, re-renders and React warnings 😊If you're not sure when your component does re-render, just put a log inside the body of your functional component, on the root level (for example before your return). Thank you so much! More on reddit.com
🌐 r/reactjs
136
265
February 22, 2021
reactjs - React Hooks and React lifecycle Methods - Stack Overflow
I am new to reactjs and react native. when started learning the basics, I found various information about the react hooks and react life cycle methods. I know there were 7 lifecycle methods before react 16.3 but now there are just 6 of them. Can anyone elaborate this lifecycle methods and react ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
freeCodeCamp
freecodecamp.org › news › react-lifecycle-methods-and-hooks-for-beginners
React Lifecycle Methods and Hooks – a Beginner's Guide
October 9, 2024 - Just a quick note: although hooks generally replace class components, there are no plans to remove classes from React. In this tutorial, you will learn about class component lifecycle methods such as componentDidMount, componentDidUpdate, componentWillUnmount, and shouldComponentUpdate.
🌐
Reddit
reddit.com › r/reactjs › does "thinking in lifecycle" still a thing given that we all use functional components nowadays?
r/reactjs on Reddit: Does "thinking in lifecycle" still a thing given that we all use functional components nowadays?
April 14, 2023 -

Just got two interviews and they all asked about this stuff. I bombed it because my knowledge about class component and lifecycle methods is really limited (only remember one component can mount, update and unmount but don't know about functions like componentWillMount and stuff)

With the new React docs, I can't find any instance of lifecycle other than "Lifecycle of an effect". So I don't really know if I am missing out one of the most fundamental pieces of React or it's just a question that interviewers like to ask...

🌐
DEV Community
dev.to › anshumanmahato › exploring-react-hooks-simplifying-state-and-lifecycle-in-functional-components-56ch
Exploring React Hooks: Simplifying State and Lifecycle in Functional Components - DEV Community
March 11, 2024 - It is known as the React Component Lifecycle. There are various methods to access these stages (see here). Only The class components had access to the state and lifecycle methods. It was not available to the functional ones. They were just simple javascript functions that took input parameters or props and returned an HTML component for rendering. All of this changed with the introduction of Hooks in React 16.8.
🌐
The Software House
tsh.io › blog › react-component-lifecycle-methods-vs-hooks
How does the React component lifecycle work? Methods & hooks
It’s all thanks to the useState and useEffect hooks – special functions that hook into React features that allow to set the initial state and use lifecycle events in functional components.
🌐
Fireart Studio
fireart.studio › digital product agency fireart › blog › technologies › react › react component lifecycle: methods and hooks
React Lifecycle: What are Methods And Hooks | Fireart
November 13, 2023 - These lifecycle methods, which can only be written or contained within a class, are obviously not applicable to functional components. React hooks, on the other hand, allow functional components to use states.
Find elsewhere
🌐
Substack
hayksimonyan.substack.com › p › react-lifecycle-methods-and-their
React Lifecycle Methods and Their Equivalent Hooks
November 1, 2023 - React components go through 3 phases during the lifecycle · Mounting Phase — In the mounting phase, a component is being created and inserted into the DOM for the first time · Update Phase — The update phase is triggered when a component’s state or props change · Unmount Phase — The unmount phase is triggered when a component is removed from the DOM · Class-based components were the traditional way of creating components in React. However, with the introduction of Hooks in React 16.8, each lifecycle method has an equivalent in functional components using React Hooks.
🌐
Wavez
wavez.github.io › react-hooks-lifecycle
React hooks lifecycle diagram
React lifecycle Hooks diagram, Functional Components visualized
🌐
Retool
retool.com › blog › the-react-lifecycle-methods-and-hooks-explained
Retool Blog | The React lifecycle: methods and hooks explained
July 9, 2025 - The useState hook gives state to the functional component, and useEffect allows you to add side effects within it (like after initial render), which aren’t allowed within the function's main body. You can also act upon updates on the state with useEffect. React has released more default hooks, but useState and useEffect are the ones you should be most familiar with. Let’s take a look at how they work and compare them to the component lifecycle we covered above.
🌐
BairesDev
bairesdev.com › home › blog › software development
React Lifecycle: Methods & Hooks In Detail
February 20, 2026 - We use React lifecycle methods ... specific behavior during each stage. React hooks provide a more concise way to manage state and side effects in functional components....
🌐
Medium
medium.com › swlh › react-lifecycle-hooks-71547ef4e7a8
React Lifecycle & Hooks. Learning React Hooks and how they… | by Adam Grider | The Startup | Medium
May 22, 2019 - Hooks were introduced to React in October 2018 as a way of incorporating state and lifecycle concepts into functional components. They’ve been blogged about ad infinitum, but they’re still relatively new in actual use.
🌐
Ionic Framework
ionicframework.com › docs › react › lifecycle
React Lifecycle: A Guide to Ionic React App Component Lifecycles
These are then passed to the underlying React useEffect hook: const [data, setData] = useState('foo'); useIonViewDidEnter(() => { console.log('ionViewDidEnter event fired'); }, [data]); All the lifecycle methods in React (componentDidMount, componentWillUnmount, etc..) are available for you to use as well.
Top answer
1 of 4
62

Here are examples for the most common lifecycles:

componentDidMount

Pass an empty array as the second argument to useEffect() to run only the callback on mount only.

function Example() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    document.title = `You clicked ${count} times`;
  }, []); // Pass an empty array to run only callback on mount only.

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

componentDidUpdate (loose)

By passing just the single argument into useEffect, it will run after every render. This is a loose equivalent because there's a slight difference here being componentDidUpdate will not run after the first render but this hooks version runs after every render.

function Example() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    document.title = `You clicked ${count} times`;
  }); // No second argument, so run after every render.

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

componentDidUpdate (strict)

The difference of this example with the example above is that the callback here would not run on initial render, strictly emulating the semantics of componentDidUpdate. This answer is by Tholle, all credit goes to him.

function Example() {
  const [count, setCount] = useState(0);

  const firstUpdate = useRef(true);
  useLayoutEffect(() => {
    if (firstUpdate.current) {
      firstUpdate.current = false;
      return;
    }

    console.log('componentDidUpdate');
  });

  return (
    <div>
      <p>componentDidUpdate: {count} times</p>
      <button
        onClick={() => {
          setCount(count + 1);
        }}
      >
        Click Me
      </button>
    </div>
  );
}

componentWillUnmount

Return a callback in useEffect's callback argument and it will be called before unmounting.

function Example() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    // Return a callback in useEffect and it will be called before unmounting.
    return () => {
      console.log('componentWillUnmount!');
    };
  }, []);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

shouldComponentUpdate

You can already achieve this on the component level using React.PureComponent or React.memo. For preventing rerendering of the child components, this example is taken from React docs:

function Parent({ a, b }) {
  // Only re-rendered if `a` changes:
  const child1 = useMemo(() => <Child1 a={a} />, [a]);
  // Only re-rendered if `b` changes:
  const child2 = useMemo(() => <Child2 b={b} />, [b]);
  return (
    <>
      {child1}
      {child2}
    </>
  )
}

getDerivedStateFromProps

Again, taken from the React docs

function ScrollView({row}) {
  let [isScrollingDown, setIsScrollingDown] = useState(false);
  let [prevRow, setPrevRow] = useState(null);

  if (row !== prevRow) {
    // Row changed since last render. Update isScrollingDown.
    setIsScrollingDown(prevRow !== null && row > prevRow);
    setPrevRow(row);
  }

  return `Scrolling down: ${isScrollingDown}`;
}

getSnapshotBeforeUpdate

No equivalent for hooks yet.

componentDidCatch

No equivalent for hooks yet.

2 of 4
2

Well, you don't really have lifecycle methods. =) But you could use the effect hook as shown here https://reactjs.org/docs/hooks-effect.html

The effect hook will be able to replicate the behavior of componentDidMount, componentDidUpdate, and componentWillUnmount

So you really don't need lifecycle methods in the component. The effect hook is taking their place instead. =)

Read the link above and you will get a few examples on how they work.

🌐
Reddit
reddit.com › r/reactjs › am i the only one who finds react lifecycle hooks super confusing?
r/reactjs on Reddit: Am i the only one who finds React lifecycle hooks super confusing?
February 22, 2021 -

It's been a year since I started learning web dev, javascript, react js and everytime i go through a react tutorial or guide, i get confused with the lifecycle hooks.

I have worked on a few small React projects and I still don't know how to incorporate lifecycle hooks in to the projects. Is their a super simple guide that demonstrates how the hooks work in real life scenarios?

Top answer
1 of 31
608
useEffect() notifies you when something changes. useEffect(() => { // execute this code }, [ // when those dependencies change ]) Using an empty array means there are no dependencies, so the code runs only on mount and unmount of the component. useEffect(() => { // this runs on mount return () => { // this runs on unmount } }, []) You can use it to monitor change and trigger an effect. const [user, setUser] = useState(null) useEffect(() => { // this runs when the user gets re-assigned }, [user]) If you want to fetch some data when mounting a component, do it like this: const [post, setPost] = useState(null) useEffect(() => { axios.get('http://dummyapi.com/posts/123').then(response => setPost(response)) }, []) This will run on mount, execute a call and store the results in your internal state. You can then display those results. The whole topic is a little more complex when you want to be correct with the exhaustive-deps lint, but this should be enough to start with. ETA: Thanks for the awards and love! I know a lot of information is missing in this comment and there are some unhandled possible difficulties, there is always way to improve and make your code better! This is just a "getting started" guide and I encourage you to study more about useEffect and also useCallback and most importantly - code your projects and watch your console logs, re-renders and React warnings 😊If you're not sure when your component does re-render, just put a log inside the body of your functional component, on the root level (for example before your return). Thank you so much!
2 of 31
68
Forget the term 'lifecycle' and start thinking 'What data change do I want to respond/re-render to'. Note: when a state hook value changes, the component re-renders and re-declares all non-hook variable values Using a hook is the concept of 'Based on what data do I want my component to update` useState - I re-render the component when my value changes. I prefer primitive values. useReducer - I have the same result as `useState` but I give you more control over my data shape and when I change. useEffect - I allow you to 'watch' different data variables, and do actions when the watched vars change. Think of me as a way to trigger reactions to change. Im also a bit special as I can run code exclusively after mount, and specifically before unmount. useLayoutEffect - I work the same way as `useEffect`, except I wait till the DOM is rendered, so I can edit DOM nodes before they show up to the user (think avoiding flicker due to style changes) useMemo - I can watch var values, and return new derived values only when the watched sources change. Try to only use me when `watched -> result` is expensive, since the code for `watching` in itself has a cost. useCallback - I work like useMemo except instead or returning values, I return functions. Use me if you don't want to re-declare a function on every render. useRef - I am special in that; when I change, no re-render happens. I can be used to 'hold onto' values across multiple render cycles. I can also be used to store references to DOM nodes. Notice, these descriptions are all about 'what can this hook do to data or values' (with the exception of unique useEffect cases). Hooks want you to forget about _how_ the component re-renders, and start thinking about _when_. Edit: formatting
🌐
Medium
medium.com › @rashmipatil24 › understanding-react-lifecycle-methods-and-hooks-28522be7d7e4
Understanding React Lifecycle Methods and Hooks | Medium
October 19, 2024 - Simplified Code: Hooks allow for more concise and readable code compared to lifecycle methods, especially when handling state and side effects in smaller, focused chunks. No Need for this: Class components require binding this to access state and props, which can lead to confusion. Hooks eliminate this issue, making functional components easier to work with. React encourages developers to use Hooks over class components for new projects due to their simplicity and flexibility.
🌐
TutorialsPoint
tutorialspoint.com › reactjs › reactjs_component_life_cycle_react_hooks.htm
Component Life Cycle Using React Hooks
values − array of values the effect depends on. React Hooks execute the executeFn only when the values are changed. This will reduce unnecessary calling of the executeFn. Let us add useEffect() Hooks in our react-clock-hook-app application.
🌐
React
legacy.reactjs.org › docs › hooks-overview.html
Hooks at a Glance – React
Hooks are functions that let you “hook into” React state and lifecycle features from function components. Hooks don’t work inside classes — they let you use React without classes.
Top answer
1 of 1
1

In React classes you had lifecycle functions and state to do things but you didn't have them in functional components. The React defs came up with hooks where you can simplify your code and re use your code better by bundling up certain functionality in a custom hook. This was previously not possible with class components. Even with mix-ins like used in Vue they now have composition api that works similarly to hooks.

Let's say you want to have counter functionality that will log when a counter changes, have an up and down function and a counter value.

In a class you need to maintain this.state.counter that you change with this.up and this.down so you could implement this in a Counter class that extends React.Component or React.PureComponent and have a component that uses a counter extends Counter but then that component can still just have one counter. In hooks you can implement a counter with a custom hook and have multiple counters in one component.

const {
  useState,
  useEffect,
  useCallback,
  useRef,
  memo,
} = React;

//hooks, also custom hooks always start with "use"
const useCounter = (name, initialValue = 1) => {
  //local counter value and function to change it
  const [counter, setCounter] = useState(initialValue);
  //ref created on mount with previous counter value
  const countRef = useRef(initialValue);
  //up and down functions created with useCallback so they
  //  will be created on mount and never change
  const up = useCallback(
    () => setCounter((c) => c + 1),
    []
  );
  const down = useCallback(
    () => setCounter((c) => c - 1),
    []
  );
  //effect that will log when counter changes
  useEffect(() => {
    if (countRef.current !== counter) {
      console.log(`counter ${name} changed to`, counter);
      countRef.current = counter;
    }
  }, [counter, name]);
  //return up, down and counter
  return { up, down, counter };
};
//using memo makes UP2 a pure component so it'll not re
//  render since up is created with useCallback and is
//  not re created therefore the props passed to UP2 
//  don't change
const UP2 = memo(function UP2({ up, name }) {
  console.log(`UP2 for ${name} will only render once`);
  return (
    <button
      onClick={() => {
        //state updates are batched in synchronous
        //  event handlers so "chaged to" will log
        //  only once
        up();
        up();
      }}
    >
      +2
    </button>
  );
});

const App = () => {
  //first counter
  const {
    up: up1,
    down: down1,
    counter: counter1,
  } = useCounter('counter one');
  //second counter
  const {
    up: up2,
    down: down2,
    counter: counter2,
  } = useCounter('counter two', 2);
  return (
    <div>
      <div>
        <button onClick={up1}>UP</button>
        <button onClick={down1}>Down</button>
        <UP2 up={up1} name={'counter one'} />
        {counter1}
      </div>
      <div>
        <button onClick={up2}>UP</button>
        <button onClick={down2}>Down</button>
        <UP2 up={up2} name={'counter two'} />
        {counter2}
      </div>
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.4/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.4/umd/react-dom.production.min.js"></script>
<div id="root"></div>

🌐
Opcito Technologies
opcito.com › blogs › lifecycle-methods-and-hooks-in-react
React lifecycle methods and hooks
May 22, 2021 - State and Lifecycle methods are the backbones of any React application, and Hooks enable functional components to implement them efficiently. Hooks allow you to use state and other React features without writing a class as they do not function inside classes.