Start naming your useEffect functions, you will thank me later

https://lemmy.blackeco.com/post/2798245

Apply to Join - Lemmy

Lemmy

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.

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.

GitHub - nickjvandyke/eslint-plugin-react-you-might-not-need-an-effect: Catch unnecessary React effects to make your code simpler, faster, and safer.

Catch unnecessary React effects to make your code simpler, faster, and safer. - nickjvandyke/eslint-plugin-react-you-might-not-need-an-effect

GitHub