We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Using useEffect Effectively – David Khourshid, React Advanced London 2022
Learn best practices for using useEffect effectively in React, including when to use and when to avoid, and discover alternative hooks for common use cases.
-
useEffect
should not be used for side effects but only for synchronization with activity -
Activity effects go in
useEffect
while action effects go in event handlers -
useEffect
should not be used for fetching data, instead useuseQuery
or similar hooks -
useEffect
should not be used for derived values, instead useuseMemo
-
Avoid using
useEffect
for synchronization, useuseSyncExternalStore
instead -
Don’t use
useEffect
for event listening, use event handlers instead -
Don’t use
useEffect
for caching, use a dedicated caching mechanism instead -
Be careful when using
useEffect
with promises and async/await -
Don’t use
useEffect
for complex conditionals, use simpler alternatives instead -
Don’t use
useEffect
for complex state machines, use a dedicated state management library instead -
Use
useEffect
only for simple, one-time effects and not for complex or ongoing processes -
Don’t override the default behavior of
useEffect
without understanding the implications -
Use
useEffect
with caution and only when necessary -
Consider using alternative hooks like
useQuery
oruseSyncExternalStore
instead ofuseEffect
-
Don’t use
useEffect
for fetching data in a component, do it in a dedicated fetch hook instead