Skip to main content

⚛ React Tips - You're misusing the React useEffect hook (probably)

Published 1 min readMarkdown
⚛ React Tips - You're misusing the React useEffect hook (probably)

This is def one of the most common mistakes I've seen in both personal and enterprise applications.

The useEffect hook exists to sync an external system (i.e. network, DOM) to your React application. That means when you're useEffect'ing to:
1. Adjust state or props when a certain value changes (in state or props)
2. Replicate legacy class based lifecycle methods

you're just doing it wrong.

With awesome packages like TanStack Query (React Query) & SWR you don't even need a useEffect to fetch data.

If you want to learn more about useEffect check out the new beta documentation on it: https://beta.reactjs.org/learn/you-might-not-need-an-effect

83 views

About the author

  • If you've got any questions feel free to DM on Twitter @reillyjodonnell

No comments yet. Be the first to comment.

More from this blog