Menu

4 useEffect Mistakes Almost Every React Dev Makes (I Ran Them All in React 19)
πŸ“°

4 useEffect Mistakes Almost Every React Dev Makes (I Ran Them All in React 19)

DEV Community: reactΒ·Muiduzzaman LipuΒ·2 days ago
#5G6IDO4l
#devtoreact#devto#dev#enter#exit
Reading 0:00
15s threshold

useEffect is the most misused hook in React. Most of the time the bug isn't obvious: the component looks fine, until your API gets hammered or the wrong user's data shows up on screen.

I took four common mistakes, ran each one in real React 19 (rendered with react-dom in a simulated browser), and counted what actually happens. Here are the results and the fix for each.

Prefer video? Here's the 3-minute version:

Mistake 1: an object in the dependency array β†’ infinite loop

function UserList ( ) { const [ users , setUsers ] = useState ( [ ] ) ; const filters = { active : true } ; // new object every render!

useEffect ( ( ) => { fetchUsers ( filters ) . then ( setUsers ) ; } , [ filters ] ) ;

return < p > { users . length } users </ p > ; }

Enter fullscreen mode

Exit fullscreen mode

React compares dependencies by reference . Every render creates a brand-new filters object, so React thinks it changed.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.