How to Solve Too Many re-renders Error in ReactJS?
Last Updated :
26 Apr, 2025
"Too many re-renderers" is a React error that happens after you have reached an infinite render loop, typically caused by code that, in a useEffect hook or the main body of the component itself, unconditionally calls state setters.
Prerequisites
Understanding too many re-renders Error
The "Too Many Re-renders" error occurs when
- The state or props in a component are updated continuously in a way that triggers repeated re-renders, creating an infinite loop.
- This can happen if state updates are triggered inside the render method or in useEffect() hooks without proper dependencies, which leads to continuous state updates and re-renders.
How React Re-renders Components
- Initially, when a component is mounted (or the component lifecycle starts), it is rendered once.
- React listens for changes to state or props. When state or props change, React will re-render the component and any child components that depend on the updated data.
- If state updates are not handled properly, React keeps re-rendering components, leading to the "Too Many Re-renders" error.
Common Causes of "Too Many Re-renders" Error
1. State Update Inside Render
Directly calling setState or useState inside the render method or component body can cause an infinite loop of re-renders, as the state updates trigger a re-render, and the update itself triggers another render.
2. State Update in useEffect Without Dependency Array
If you use setState inside a useEffect hook without providing a proper dependency array, it will trigger a re-render after each render, causing an infinite loop.
3. Conditional State Updates
If a state update is being triggered under certain conditions in a way that causes it to always meet those conditions, it can cause repeated state changes and re-renders.
4. Event Handlers Causing State Updates on Every Render
If event handlers like onClick or onChange are directly updating the state in such a way that the component is constantly re-rendering, this can also lead to the "Too Many Re-renders" error.
5. Using Functions Inside useEffect that Modify State Continuously
If a function inside useEffect continuously updates state based on a condition that keeps triggering the effect, it can lead to an infinite re-render loop. For example, using state values directly inside useEffect that causes frequent updates.
Tips to avoid too many re-renders errors in React
Encountering a "too many re-renders" error can be frustrating.
Remember the below tips to avoid the error in React
- Don't change the state in the main body of the component.
- Use the useEffect hook very cautiously. The second parameter of useEffect is an array of states based on the useEffect will call. So don't update those states in useEffect otherwise, it will rerender the component again and again.
- Use React shouldComponentUpdate: React shouldComponentUpdate is a method for optimizing performance, which tells React to stop re-rendering a component, even though it might have changed the state or prop values. Using this approach only if a part stays unchanged or pure while it is used. You are expected to return a Boolean value with the React shouldComponentUpdate method. Return true if it needs to re-render or false to avoid being re-render.
Preventing Too Many re-renders Error in ReactJS
Example 1: Below is an example of how to use React shouldComponentUpdate. I've built 2 components of React in this code. One is a part of the greeting, and the other is the app component. During the render lifecycle, each React component is a console logging a message.
JavaScript
// Filename- App.js
import React from "react";
class Greeting extends React.Component {
render() {
console.log("Greeting - Render lifecycle");
return <h1>Geeksforgeeks</h1>;
}
}
class App extends React.Component {
render() {
console.log("App - Render lifecycle");
return <Greeting />;
}
}
export default App;
Output

Example 2: Next, in the componentDidMount React lifecycle, I will add the React state, and update the state value.
JavaScript
// Filename- App.js
import React from "react";
class Greeting extends React.Component {
render() {
console.log("Greeting - Render lifecycle");
return <h1>Geeksforgeeks</h1>;
}
}
class App extends React.Component {
state = {
greeted: false,
};
componentDidMount() {
this.setState({ greeted: true });
}
render() {
console.log("App - Render lifecycle");
return <Greeting />;
}
}
export default App;
Step to run the application: Open the terminal and type the following command.
npm start
Output
Example 3: Use the shouldComponentUpdate hook when it is clear that at all times a component we are creating will be static.
JavaScript
// Filename - App.js
import React from "react";
class Greeting extends React.Component {
shouldComponentUpdate() {
console.log("Greeting - shouldComponentUpdate lifecycle");
return false;
}
render() {
console.log("Greeting - Render lifecycle");
return <h1>Geeksforgeeks</h1>;
}
}
class App extends React.Component {
state = {
greeted: false,
};
componentDidMount() {
this.setState({ greeted: true });
}
render() {
console.log("App - Render lifecycle");
return <Greeting />;
}
}
export default App;
Output

Conclusion
The "Too many re-renders" error in React occurs due to infinite re-render loops, usually due to improper state update and incorrect hook usage. To avoid and resolve this error ensure state updates are correct and hooks are used properly.
Similar Reads
How to Use Flux to Manage State in ReactJS?
State management in ReactJS is important for building dynamic and responsive applications. Flux, an architecture for managing state, provides a structured approach to handle data flow and state changes efficiently in React applications. In this article, we will explore the Flux to Manage State in Re
5 min read
How to combine multiple reducers in ReactJS ?
To combine multiple reducers in React JS we have a function called combineReducers in the redux. This basically helps to combine multiple reducers into a single unit and use them. Approach In React, to combine and implement multiple reducers combineReducers methods are used. It manages multiple redu
4 min read
How to improve slow React application rendering ?
Slow React application rendering as its name suggests is a small or large delay in rendering elements. There may be multiple reasons for that. React uses the concept of Virtual DOM. All the elements in React are rendered using the render method in which we have to provide an id of an element (mostly
4 min read
How to optimize React component to render it ?
ReactJS mainly depends upon the props (which are passed to it) and the state of the Component. Hence to reduce the number of times Component renders we can reduce the props and state it depends upon. This can be easily done by separating the logic of one component into several individual child compo
3 min read
How to call function inside render in ReactJS ?
In React JS, the render method is a fundamental part of a component's lifecycle. It is responsible for rendering the component's JSX markup onto the DOM. While the render method itself should primarily handle rendering JSX, there are scenarios where you may need to call a function inside the render
3 min read
How to prevent page from rendering before redirect in ReactJS ?
ReactJS is a popular front-end framework that allows developers to create dynamic and responsive web applications. One common issue that developers face when working with ReactJS is preventing a page from rendering before a redirect is complete. This can lead to issues such as slow loading times, br
4 min read
How To Render An Array Of Objects In ReactJS?
Rendering dynamic data in ReactJS is one of the most fundamental tasks when building interactive web applications. One of the most common scenarios is rendering an array of objects, such as a list of users, products, or posts, in the user interface (UI). To render an array of objects in React we wil
4 min read
How re-render a component without using setState() method in ReactJS ?
In React, to re-render a class-based component with an updated state we generally use the setState() method. But instead, we can use other methods to re-render a component without using setState(). Prerequisites:Â NPM & Node.jsReact JSReactJS propsReactJS forceUpdate() methodApproaches to re-rend
3 min read
How to Create Store in React Redux ?
React Redux is a JavaScript library that is used to create and maintain state in React Applications efficiently. Here React Redux solves the problem by creating a redux store that stores the state and provides methods to use the state inside any component directly or to manipulate the state in a def
4 min read
How to Update Parent State in ReactJS ?
Updating the parent state in React involves passing a callback function as a prop to the child that triggers the state change and updates the data in the state.Prerequisites:ReactJSReact State and PropsReact Components ApproachTo update parent state in React we will pass a function as a prop to the
3 min read