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.
-
useEffectshould not be used for side effects but only for synchronization with activity -
Activity effects go in
useEffectwhile action effects go in event handlers -
useEffectshould not be used for fetching data, instead useuseQueryor similar hooks -
useEffectshould not be used for derived values, instead useuseMemo -
Avoid using
useEffectfor synchronization, useuseSyncExternalStoreinstead -
Don’t use
useEffectfor event listening, use event handlers instead -
Don’t use
useEffectfor caching, use a dedicated caching mechanism instead -
Be careful when using
useEffectwith promises and async/await -
Don’t use
useEffectfor complex conditionals, use simpler alternatives instead -
Don’t use
useEffectfor complex state machines, use a dedicated state management library instead -
Use
useEffectonly for simple, one-time effects and not for complex or ongoing processes -
Don’t override the default behavior of
useEffectwithout understanding the implications -
Use
useEffectwith caution and only when necessary -
Consider using alternative hooks like
useQueryoruseSyncExternalStoreinstead ofuseEffect -
Don’t use
useEffectfor fetching data in a component, do it in a dedicated fetch hook instead