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, ...
🌐
freeCodeCamp
freecodecamp.org › news › react-hooks-useeffect-usestate-and-usecontext
How to Use React Hooks – useEffect, useState, and useContext Code Examples
December 4, 2023 - In this example, the useEffect hook is used to fetch data from an API when the component mounts. The second argument of useEffect is an array of dependencies. If the dependencies change between renders, the effect will run again.
🌐
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.
🌐
GreatFrontEnd
greatfrontend.com › blog › 100-react-interview-questions-straight-from-ex-interviewers
100+ React Interview Questions Straight from Ex-interviewers | Blog
July 16, 2025 - To re-render the view on browser resize, use the useEffect hook to listen for the resize event and update state.
🌐
Devhandbook
devhandbook.com › react › hooks › useeffect
useEffect | Dev Handbook
useEffect() invokes the clean up function we return from the callback function
Find elsewhere
🌐
React
react.dev › reference › react › useRef
useRef – React
useEffect(() => { // ✅ You can read or write refs in effects · myRef.current = 123; }); // ... function handleClick() { // ✅ You can read or write refs in event handlers · doSomething(myOtherRef.current); } // ... } If you have to read or write something during rendering, use state instead.
🌐
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.
🌐
DEV Community
dev.to › mpodlasin › react-useeffect-hook-explained-in-depth-on-a-simple-example-19ec
React.useEffect hook explained in depth on a simple example - DEV Community
September 30, 2020 - This will allow us to compare the difference in the console outputs, when we click repeatedly on the counter button. Just remember to include [count] array as a second parameter to useEffect.
🌐
Medium
medium.com › @greennolgaa › mastering-useeffect-in-react-js-a-comprehensive-guide-709a8024cb60
Mastering useEffect in React.js: A Comprehensive Guide | by Olga Green | Medium
July 27, 2023 - In this comprehensive blog post, we will dive deep into the world of useEffect in React js. We will explore its purpose, syntax, best practices, and various use cases.
🌐
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)
🌐
AWS Teacher
awsteacher.com › home › web development › react
Everything you need to know about React's useEffect - AWS Teacher
January 14, 2023 - useEffect is a Hook in React that ... to a component’s props or state. useEffect takes two arguments: a callback function and an array of dependencies....
🌐
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.
🌐
LogRocket
blog.logrocket.com › home › how to use the useeffect hook in react: a complete guide
How to use the useEffect hook in React: A complete guide - LogRocket Blog
June 3, 2025 - Subsequent renders: You can pass a dependency array as the second argument to the useEffect Hook. This array contains variables or values that the effect depends on. Any change in these variables will re-render the component.
🌐
Telerik
telerik.com › blogs › breakdown-react-useeffect-hook
A Breakdown of the React useEffect Hook
January 31, 2023 - The second argument of the useEffect hook is optional and is a dependency list that allows us to tell React to skip applying the effect only until in certain conditions. In other words, the second argument of the useEffect hook allows us to limit when the effect is to be run.
🌐
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.
🌐
Dmitri Pavlutin
dmitripavlutin.com › react-useeffect-explanation
A Simple Explanation of React.useEffect()
January 28, 2023 - Put your side-effect logic into the callback function, then use the dependencies argument to control when you want the side-effect to run. That's the sole purpose of useEffect().