Hacker News new | past | comments | ask | show | jobs | submit login

There is only one case where you should be fetching inside of useEffect, and that is with an empty dependency array to get data on first render. Pretty simple and easy to wrap your head around.

Everything else is triggered by event handlers. I work on a 70Loc react app and useEffect is used maybe once outside of this context. You really don't need it.

And I don't know what you mean by "listening to browser events" with useEffect. You really just need to use onClick and onChange.

You also don't need it to set state, you need calculated constant assignments.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: