r/reactjs • • Apr 30 '26

Discussion Finally realized how much i was abusing useEffect, and deleting them is the best feeling ever..

[removed]

293 Upvotes

85 comments sorted by

View all comments

137

u/michaelfrieze Apr 30 '26

LLM’s love to use useEffect for some reason, even when I tell it not to. It’s so annoying.

153

u/___bridgeburner Apr 30 '26

Probably because a lot to people misues useEffect, and LLMs are trained on that same data

28

u/[deleted] Apr 30 '26

[removed] — view removed comment

5

u/anonyuser415 May 01 '26

And it compounds. Most code-oriented LLMs prefer following patterns in the repo.

If vibe coded slop is getting merged with crappy useEffects, more and more will appear.

This is why being a stickler in code review pays off

16

u/kwietog Apr 30 '26

I have you might not need an effect article pasted in my default prompt settings saying "if you think you want to use useEffect, read this article and reconsider".

It's still sometimes tries to use it.

6

u/michaelfrieze Apr 30 '26

Yeah, I have it in my AGENTS.md but it just ignores it most of the time. I often have to paste the URL in my prompts.

1

u/TalonKAringham May 01 '26

I’m not AI, I swear, but can you send it my way?

7

u/Raunhofer Apr 30 '26

And callbacks & memos. At least codex and cc generate really mid React.

1

u/michaelfrieze Apr 30 '26 edited Apr 30 '26

Yeah, I make it clear in my AGENTS.md that I'm using the compiler and it still heavily uses callbacks & memos. I have given up on caring about this specifically, but I do pay extra attention to useEffect because it can do a lot more damage.

9

u/Justin_Passing_7465 Apr 30 '26

Think of the shittiest react code that you ever saw the dumbest dev in your company write. That code was used to train all of the LLMs.

1

u/bzbub2 Apr 30 '26 edited Apr 30 '26

they do (and weird non idiomatic useref too...i always gotta be like no stoppp) but you can paste the URL of you may not need an effect in prompt and it's pretty good at removing unneeded useeffects

1

u/michaelfrieze Apr 30 '26

Yeah, I paste that URL all the time.

-2

u/SawToothKernel Apr 30 '26

It's not a problem if you guide them properly. This is my starter for most side projects and I never have an issue with that.

https://github.com/andyjessop/starter

4

u/michaelfrieze Apr 30 '26

Sorry, but I would never use a starter for a real project.

Also LLMs never fully follow things like agent rules and skills. They will sometimes add useEffect regardless. I find most success by reminding them in every prompt to read react docs or the docs of whatever tool I am working with. I add the "you might not need useEffect" URL in almost every react related prompt these days. And even then, they still fucking do it on occasion.

2

u/michaelfrieze Apr 30 '26

Also, your useEffect rules are not enough: https://github.com/andyjessop/starter/blob/main/.agents/rules/frontend.md

You should add this URL in there or at least copy most of this from the react docs: https://react.dev/learn/you-might-not-need-an-effect

Another thing really helpful for hooks in general is this ESLint plugin. It doesn't help much with useEffect spam, but I find it helps LLMs a lot with hooks. https://react.dev/reference/eslint-plugin-react-hooks

6

u/KnifeFed Apr 30 '26

1

u/michaelfrieze Apr 30 '26

Yeah, I saw this posted somewhere else in this thread.

I'm surprised the react team hasn't released something like this officially. There must be a reason, right?

2

u/nickjvandyke May 01 '26

When I first posted it here almost a year ago, some people said they tried but gave up haha. It was pretty dang hard. It's stable now but its initial experimentation fits a community plugin better as well.

→ More replies (3)
→ More replies (1)

1

u/SawToothKernel Apr 30 '26

What do you mean by not enough? I've not really had any issue with use effect. The architecture in that file pretty much dictates how features should be written.

1

u/SawToothKernel Apr 30 '26

Do you always start from scratch for side projects?

1

u/michaelfrieze Apr 30 '26

Yeah. I don’t even like letting AI create a project. I always set it up myself first.

1

u/SawToothKernel Apr 30 '26

I get where you're coming from, but for side projects I usually just want to start coding. I don't want to take half an hour of setting things up first.

They never last anyway, so I don't see the point in wasting time on boilerplate.

1

u/michaelfrieze Apr 30 '26

It just doesn't take me long to setup a project. I know what I want.