Start naming your useEffect functions, you will thank me later

https://neciudan.dev/name-your-effects

12 points · 2 comments · view on lemmy.world

2 Comments

beirut_bootleg@programming.dev · 1 pts · 172d (1 reply)

When used properly like the websocket example it's clear what it does. If you're using useEffect to sync props and state, then yes, you're going to have trouble reasoning through it. The solution is to not use useEffect because you're no longer writing React, you're writing Angular. No named function expression will fix that.

BlackEco@lemmy.blackeco.com · 1 pts · 172d

The author actually addresses this point, explaining that since you name your effects, you should realise when they are used to sync states and take action.

As a side-note, eslint-plugin-react-you-might-not-need-an-effect might be better suited to catch these.