There are specific times you'll want to use useEffect without a dependency array. Probably the most commom situation is keeping a ref up-to-date with external properties. ref.current should not be updated during the render phase. Instead, if you have something that could change beyond you control (such as a property that is a function), and you want to use it in an effect, you'll want to update the ref in an arrayless effect: function Component({ value, onChange }) { const onChangeRef = useRef(onChange); useEffect(() => { onChangeRef.current = onChange; }); useEffect(() => { onChangeRef.current?.(value); }, [value]); ... } This lets you call the function without worrying about how the function might change. Answer from landisdesign on reddit.com
Medium
ogroetz.medium.com › react-hooks-useeffect-80478a49015b
React Hooks — useEffect
December 24, 2021 - When you only want to do something when a specific element on your page changes, you will want to incorporate useEffects second parameter, aka the dependency array. This second parameter is always an array, and whatever is passed into this array, ...
Videos
useEffect React Hook Tutorial (2024) - What YOU need to know - YouTube
12:48
How To Actually Use The useEffect Hook In Modern React.js - YouTube
19:14
#17 React useEffect Hook Simplified with examples - YouTube
01:44
useEffect in React Explain in under 2 minutes - YouTube
React useEffect() hook introduction
Expo Documentation
docs.expo.dev › expo sdk › splashscreen
SplashScreen - Expo Documentation
import { Stack } from 'expo-router'; import * as SplashScreen from 'expo-splash-screen'; import { useEffect, useState } from 'react'; // Keep the splash screen visible while we fetch resources SplashScreen.preventAutoHideAsync(); export default function RootLayout() { const [isReady, setIsReady] = useState(false); useEffect(() => { async function doAsyncStuff() { try { // do something async here } catch (e) { console.warn(e); } finally { setIsReady(true); } } doAsyncStuff(); }, []); useEffect(() => { if (isReady) { SplashScreen.hide(); } }, [isReady]); if (!isReady) { return null; } return <Stack />; }
LogRocket
blog.logrocket.com › home › understanding react’s useeffect cleanup function
Understanding React’s useEffect cleanup function - LogRocket Blog
December 16, 2024 - As a side note before we continue: useEffects can be made to run once by simply passing an empty array to the dependency list. When you provide an empty array as the dependency list for useEffect, it indicates that the effect does not depend on any values from the component’s state or props.
Devhandbook
devhandbook.com › react › hooks › useeffect
useEffect | Dev Handbook
useEffect() invokes the clean up function we return from the callback function
Reddit
reddit.com › r/reactjs › is a useeffect without a 2nd argument the same as a regular function call?
r/reactjs on Reddit: Is a UseEffect without a 2nd argument the same as a regular function call?
January 13, 2023 -
I just read that a UseEffect without a 2nd argument re-runs on every render or re-render of the component.
This defeats the whole purpose of the UseEffect and would be equivalent to just having an anonymous function or a function call (or simply running code) from within the body of the component, which would run each time the component re-renders.
Is my logic correct? or are the 2 still different?
Top answer 1 of 15
16
There are specific times you'll want to use useEffect without a dependency array. Probably the most commom situation is keeping a ref up-to-date with external properties. ref.current should not be updated during the render phase. Instead, if you have something that could change beyond you control (such as a property that is a function), and you want to use it in an effect, you'll want to update the ref in an arrayless effect: function Component({ value, onChange }) { const onChangeRef = useRef(onChange); useEffect(() => { onChangeRef.current = onChange; }); useEffect(() => { onChangeRef.current?.(value); }, [value]); ... } This lets you call the function without worrying about how the function might change.
2 of 15
12
Love this question! It’s actually one of my favorite questions to ask developers when they’re interviewing for my team. Well, not specifically this, but more general like “what are the three different ways you can configure the 2nd arg/dependency array in the useEffect and what are their effects“? Not many people get the third option of omitting the array correct, which is fine. True use cases for omitting the dependency array are very rare. I think I’ve maybe used it once or twice in my career so far (other than when I accidentally did it as a junior dev causing infinite loops, like we all do). One of the use cases I had was I designed a code-snippet website, similar to Gists, and the component, whose children were all content blocks of saved code, had to run a side-effect to apply code highlighting to all
html elements, so it was a simple solution to just do a UE on the parent component that ran the script on re-renders.
React
react.dev › reference › react › useEffect
useEffect – React
If your Effect wasn’t caused by an interaction (like a click), React will generally let the browser paint the updated screen first before running your Effect. If your Effect is doing something visual (for example, positioning a tooltip), and the delay is noticeable (for example, it flickers), replace useEffect with useLayoutEffect.
Strapi
docs.strapi.io › preview
Preview | Strapi 5 Documentation
using a query parameter, having something like /your-path?preview=true (this is, for instance, how Nuxt works)
SWR
swr.vercel.app
SWR
SWR is a minimal API with built-in caching, revalidation, and request deduplication. It keeps your UI fast, consistent, and always up to date — with a single React hook · Pass a key and a fetcher to useSWR. The hook manages the request, caches the response, and keeps data fresh.
freeCodeCamp
freecodecamp.org › news › react-useeffect-absolute-beginners
The React useEffect Hook for Absolute Beginners
March 1, 2022 - If you forget to provide your dependencies correctly and you are setting a piece of local state when the state is updated, the default behavior of React is to re-render the component. And therefore, since useEffect runs after every single render without the dependencies array, we will have an infinite loop.
W3Schools
w3schools.com › react › react_useeffect.asp
React useEffect
useEffect runs on every render. That means that when the count changes, a render happens, which then triggers another effect. This is not what we want. There are several ways to control when side effects run. We should always include the second parameter which accepts an array.
NamasteDev
namastedev.com › home › react › react useeffect hook deep dive
React useEffect Hook Deep Dive - NamasteDev Blogs
April 24, 2025 - In React, rendering a component is a pure function. When the function executes, it should not cause unintended changes. This is where the useEffect hook comes into play, allowing you to encapsulate side effects in functional components.