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
🌐
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.
🌐
W3Schools
w3schools.com › react › react_useeffect.asp
React useEffect Hooks
We should always include the second parameter which accepts an array. We can optionally pass dependencies to useEffect in this array. ... useEffect(() => { //Runs on the first render //And any time any dependency value changes }, [prop, state]); ...
People also ask

What is the useEffect hook used for in React?
The useEffect hook in React allows developers to manage side effects like data fetching, DOM manipulation, or subscriptions within functional components. It helps control when these side effects should be executed by specifying dependencies.
🌐
dhiwise.com
dhiwise.com › post › understanding-the-importance-of-the-useeffect-dependency-array-in-react
UseEffect Dependency Array: Best Practices For React ...
Why is the dependency array important in useEffect?
The dependency array in useEffect tells React when to re-run the effect. It ensures the effect only runs when specified state or prop values change, improving performance and avoiding unnecessary renders.
🌐
dhiwise.com
dhiwise.com › post › understanding-the-importance-of-the-useeffect-dependency-array-in-react
UseEffect Dependency Array: Best Practices For React ...
What happens if you don’t pass a dependency array to useEffect?
Without a dependency array, the effect runs after every render. This can lead to performance issues and bugs since the effect won't re-run based on changes in specific dependencies.
🌐
dhiwise.com
dhiwise.com › post › understanding-the-importance-of-the-useeffect-dependency-array-in-react
UseEffect Dependency Array: Best Practices For React ...
🌐
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 › learn › you-might-not-need-an-effect
You Might Not Need an Effect – React
import { useState, useEffect } from 'react'; import { initialTodos, createTodo } from './todos.js'; export default function TodoList() { const [todos, setTodos] = useState(initialTodos); const [showActive, setShowActive] = useState(false); const [activeTodos, setActiveTodos] = useState([]); const [visibleTodos, setVisibleTodos] = useState([]); const [footer, setFooter] = useState(null); useEffect(() => { setActiveTodos(todos.filter(todo => !todo.completed)); }, [todos]); useEffect(() => { setVisibleTodos(showActive ?
🌐
DhiWise
dhiwise.com › post › understanding-the-importance-of-the-useeffect-dependency-array-in-react
UseEffect Dependency Array: Best Practices For React ...
August 13, 2025 - The dependency array is the second parameter you pass to the useEffect hook. It tells React when to re-run your useEffect callback function.
Find elsewhere
🌐
React
legacy.reactjs.org › docs › hooks-effect.html
Using the Effect Hook – React
Placing useEffect inside the component lets us access the count state variable (or any props) right from the effect. We don’t need a special API to read it — it’s already in the function scope. Hooks embrace JavaScript closures and avoid introducing React-specific APIs where JavaScript already provides a solution.
🌐
DEV Community
dev.to › nibble › what-is-useeffect-hook-and-how-do-you-use-it-1p9c
What is useEffect hook and how do you use it? - DEV Community
June 30, 2020 - From the Previous section , we said the first argument to useEffect is a function called effect. effect takes no parameters and it MUST return either a function or undefined. If it returns a function, then the function returned is called cleanup. ...
🌐
Educative
educative.io › answers › what-is-the-useeffect-hook-in-react
What is the useEffect Hook in React?
Lines 10–27: Since the callback function in useEffect Hook cannot be directly asynchronous, we define an async function retrieveOldMessages within the callback and call it immediately. This approach allows us to handle asynchronous tasks like fetching data without issues. Line 28: After the messages are fetched, we set the userActive status to true, indicating that the user is active in the chat. Line 29: We pass an empty array [] as the dependencies parameter to ensure useEffect Hook only runs once on the initial render, mimicking the componentDidMount method in class components.
🌐
React
legacy.reactjs.org › docs › hooks-reference.html
Hooks API Reference – React
While passing [] as the second argument is closer to the familiar componentDidMount and componentWillUnmount mental model, there are usually better solutions to avoid re-running effects too often. Also, don’t forget that React defers running useEffect until after the browser has painted, so doing extra work is less of a problem.
🌐
Medium
medium.com › trabe › react-useeffect-hook-44d8aa7cccd0
React useEffect Hook. What is the useEffect hook, how does it… | by Ceci García García | Trabe | Medium
April 3, 2019 - As long as we only want our effect (subscribe to resizes) to be called once, we pass an empty array as the second parameter of the function useEffect. An effect can optionally return a function (the cleanup function) that React will call when the component unmounts and before running the effect next time.
🌐
Hygraph
hygraph.com › blog › react-useeffect-a-complete-guide
React useEffect() - A complete guide | Hygraph
January 21, 2026 - Breaking down the above structure, the callback function inside useEffect runs after the component renders. It contains the side effect logic. The second argument, the array [dependencies], tells React to re-run the effect whenever any value in the array changes.
🌐
Dave Ceddia
daveceddia.com › useeffect-hook-examples
How the useEffect Hook Works (with Examples)
A common mistake people make is to pass the [] to useEffect even though the effect does depend on some variables. If you’re using Create React App or the React ESLint rules, you’ll get a warning about this in the browser console.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › reactjs-useeffect-hook
React useEffect Hook %%page%% %%sep%% %%sitename%% - GeeksforGeeks
Dependencies array: React re-runs the effect if any of the values in this array change. useEffect runs side effects after rendering and manages updates based on dependencies.
Published   2 weeks ago
🌐
Overreacted
overreacted.io › a-complete-guide-to-useeffect
A Complete Guide to useEffect — overreacted
March 9, 2019 - React can’t guess what the function does without calling it. (The source doesn’t really contain specific values, it just closes over the name prop.) This is why if you want to avoid re-running effects unnecessarily, you can provide a dependency array (also known as “deps”) argument to useEffect:
🌐
Zipy
zipy.ai › blog › useeffect-hook-guide
The ultimate guide to using the useEffect hook in React
August 13, 2025 - In this effect, we set the document ... a fairly simple syntax. It takes two parameters: a callback function that represents the side effects and an optional dependency array....
🌐
KnowledgeHut
knowledgehut.com › home › blog › software development › how to use useeffect in react js: a beginner-friendly guide
React useEffect() Hook: Structure, Usage, Examples & Tips
July 22, 2025 - Confused by useEffect in React JS? Learn how this hook works, when to use it, and how to handle side effects with clean, working code examples.