New May 13, 2026

Why does useEffect cause an infinite re-render loop in React? [duplicate]

Libraries, Frameworks, etc. All from Newest questions tagged reactjs - Stack Overflow View Why does useEffect cause an infinite re-render loop in React? [duplicate] on stackoverflow.com

I'm currently learning React hooks and encountered an issue where my component keeps re-rendering infinitely.

I expected the effect to run only once after updating the state, but instead the component continuously re-renders.

Here is a simplified example:

const [data, setData] = useState(null);

useEffect(() => { setData("hello"); }, [data]);

Scroll to top