How to Solve Too Many re-renders Error in ReactJS?
Last Updated :
23 Jul, 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
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
React Fundamentals
React IntroductionReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability. "Hello, World!" Program in ReactJavaScriptimport React from 'react'; function App() {
6 min read
React Environment SetupTo run any React application, we need to first setup a ReactJS Development Environment. In this article, we will show you a step-by-step guide to installing and configuring a working React development environment.Pre-requisite:We must have Nodejs installed on our PC. So, the very first step will be
3 min read
React JS ReactDOMReactDOM is a core React package that provides DOM-specific methods to interact with and manipulate the Document Object Model (DOM), enabling efficient rendering and management of web page elements. ReactDOM is used for: Rendering Components: Displays React components in the DOM.DOM Manipulation: Al
2 min read
React JSXJSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
5 min read
ReactJS Rendering ElementsIn this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are the smallest building blocks of a React application. They are different from DOM elements
3 min read
React ListsIn lists, React makes it easier to render multiple elements dynamically from arrays or objects, ensuring efficient and reusable code. Since nearly 85% of React projects involve displaying data collectionsâlike user profiles, product catalogs, or tasksâunderstanding how to work with lists.To render a
4 min read
React FormsForms are an essential part of any application used for collecting user data, processing payments, or handling authentication. React Forms are the components used to collect and manage the user inputs. These components include the input elements like text field, check box, date input, dropdowns etc.
5 min read
ReactJS KeysA key serves as a unique identifier in React, helping to track which items in a list have changed, been updated, or removed. It is particularly useful when dynamically creating components or when users modify the list. When rendering a list, you need to assign a unique key prop to each element in th
4 min read
Components in React
React Lifecycle In React, the lifecycle refers to the various stages a component goes through. These stages allow developers to run specific code at key moments, such as when the component is created, updated, or removed. By understanding the React lifecycle, you can better manage resources, side effects, and perfo
7 min read
React Hooks
Routing in React
Advanced React Concepts
React Projects