🌐
DEV Community
dev.to β€Ί csituma β€Ί why-we-use-empty-array-with-useeffect-iok
Why we use empty array with UseEffect - DEV Community
December 10, 2022 - In this example, useEffect is used ... argument to useEffect means that the fetchData function will only be called on initial render, and not on subsequent renders when the data state changes....
Discussions

Bug: Clean up useEffect given [] empty dependency array causes a tedious linter error
Below is an example component (full component LINK) which is causing a linter error if not disabled. This issue propbably relates to #16265 ;-) A clean up useEffect given an empty dependency array, using a props method causes an error Re... More on github.com
🌐 github.com
11
September 4, 2023
New hook for useEffect and empty array
Do you want to request a feature or report a bug? New feature What is the current behavior? The second parameter to useEffect isn't especially clear or explicit. Empty array for "observe n... More on github.com
🌐 github.com
3
November 11, 2019
Bug: useEffect with no dependencies always fires a warning
Using useEffect with an empty dependency array will fire up the warning 'react-hooks/exhaustive-deps'. However, using useEffect with an empty dependency list should be a safe praxis when us... More on github.com
🌐 github.com
2
January 1, 2021
reactjs - useEffect is now working when dependency is empty array - Stack Overflow
I have below code. when perioddata's state changes, it runs the first useEffect with dependency [perioddata]. In there, it updates resultData state. After resultData updates, it runs the second use... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com β€Ί facebook β€Ί react β€Ί issues β€Ί 27333
Bug: Clean up useEffect given [] empty dependency array causes a tedious linter error Β· Issue #27333 Β· facebook/react
September 4, 2023 - type AscensionModalProps = { open: boolean; onClose: () => void; member: GangMember; onAscend: () => void; }; export function AscensionModal(props: AscensionModalProps): React.ReactElement { const gang = useGang(); useRerender(1000); //Cleanup if modal is closed for other reasons, ie. ns.gang.ascendMember() useEffect(() => { return () => { props.onClose(); }; }, []); // eslint-disable-line react-hooks/exhaustive-deps // dependency array must be given and empty or modal will not open // React error wants 'props' in dependency or don't use 'props'.
Author Β  myCatsName
🌐
React
react.dev β€Ί reference β€Ί react β€Ί useEffect
useEffect – React
If you omit this argument, your Effect will re-run after every commit of the component. See the difference between passing an array of dependencies, an empty array, and no dependencies at all. ... useEffect is a Hook, so you can only call it at the top level of your component or your own Hooks.
🌐
GitHub
github.com β€Ί facebook β€Ί react β€Ί issues β€Ί 17342
New hook for useEffect and empty array Β· Issue #17342 Β· facebook/react
November 11, 2019 - Empty array for "observe nothing" and undefined for essentially "observe everything." Since the former case is so common (used where componentDidMount would have been used for things like ajax calls), what about a verbosely named dedicated hook?
Author Β  jp-simons
🌐
Medium
medium.com β€Ί @techsolutionsx β€Ί deep-dive-understanding-why-useeffect-fires-twice-with-an-empty-dependency-array-in-react-bc577a358807
Deep Dive: Understanding Why useEffect Fires Twice with an Empty Dependency Array in React | by π•Ώπ•Ύπ–”π–‘π–šπ–™π–Žπ–”π–“π–˜π–ƒ | Medium
September 21, 2023 - The first execution of useEffect with an empty dependency array occurs during the initial render of the component. This is intentional and serves to ensure that any necessary side effects are carried out when the component first appears in the DOM.
Find elsewhere
🌐
GitHub
github.com β€Ί facebook β€Ί react β€Ί issues β€Ί 20530
Bug: useEffect with no dependencies always fires a warning Β· Issue #20530 Β· facebook/react
January 1, 2021 - Using useEffect with an empty dependency array will fire up the warning 'react-hooks/exhaustive-deps'. However, using useEffect with an empty dependency list should be a safe praxis when using it as the equivalent of onComponentDidMount....
Author Β  miquelvir
🌐
John Kavanagh
johnkavanagh.co.uk β€Ί home β€Ί articles β€Ί why use empty dependency array in react's useeffect
Why Use Empty Dependency Array in React's useEffect, by John Kavanagh
October 28, 2025 - To wrap things up, the dependency array in React's useEffect hook plays a crucial role in determining just how and when your effect should run. Using an empty array ensures that the effect only runs once when the component first mounts.
🌐
Codedamn
codedamn.com β€Ί news β€Ί react js
useEffect dependency array in React.js – Complete Guide
June 2, 2023 - The useEffect manages an array that contains the state variables or functions which are kept an eye for any changes. These changes then trigger the callback function. The most basic dependency array would be an empty array. The empty array indicates that the useEffect doesn’t have any dependencies on any state variables.
🌐
Medium
medium.com β€Ί devil-is-in-the-details β€Ί dependency-array-in-useeffect-hook-d73e0ef2ab33
Dependency array in useEffect hook | by Shreejit Rajbanshi | Devil is in the Details | Medium
November 20, 2022 - Any unrelated state change will ... of the component }) An empty array simply means that there are no dependencies that will trigger the callback within it....
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 74079165 β€Ί useeffect-is-now-working-when-dependency-is-empty-array
reactjs - useEffect is now working when dependency is empty array - Stack Overflow
const [perioddata, setPerioddata] = useState([]); const [resultData, setResultData] = useState([]); useEffect(() => { console.log("perioddata", perioddata); let resultdata = resultDateFunc(perioddata); setResultData(resultdata); }, [perioddata]); useEffect(() => { console.log("resultdata", resultData); }, [resultData]); At first it runs well. When I console.log all these, it shows correct each data. perioddata (6) [{…}, {…}, {…}, {…}, {…}, {…}] resultdata (2) [{…}, {…}] Later, I change perioddata and it becomes empty array.
🌐
Reddit
reddit.com β€Ί r/reactjs β€Ί what is the purpose of useeffect without a dependency array?
r/reactjs on Reddit: What is the purpose of useEffect without a dependency array?
March 3, 2022 -

I use useEffect all the time in my applications, but I've never understood the difference between having code inside a useEffect with no dependency array, and just running it in the component itself.

From the documentation. What is the difference between this

function Example() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    document.title = `You clicked ${count} times`;
  });
}

and this?

function Example() {
  const [count, setCount] = useState(0);
  document.title = `You clicked ${count} times`;
}

wont both run on every render?

Edit: thanks for all the helpful responses. It seems like my intuition was almost right. It does behave slightly differently, but almost never in a way you want. However it would be good for protecting DOM manipulating functions for SSR.

🌐
Vercel
pak-anonymous.vercel.app β€Ί Skipping-Effect(empty-array-dependency)
How to do skipping effects (empty array dependency) in useEffect(React)
its works similar to componentDidMount if we passed the empty array.without an Array dependency,the effect function will be run after every single render. 1import "./styles.css"; 2import React ,{useEffect,useState} from "react" 3 4export default function WithEmptyArray() { 5 const[change,s...
🌐
Reddit
reddit.com β€Ί r/reactjs β€Ί this is why you should pass an empty array into useeffect
r/reactjs on Reddit: This is why you should pass an empty array into useEffect
January 31, 2020 -
useEffect(() => {
    (async() => {
        // insert a row into database on server
    })();

    return () => {
        console.log('unmounted');
        (async() => {
            // delete row in database on server
        })();
    }
});
  1. On initial mount of the component, the returned function will be called resulting on whatever I created on my server to be deleted

  2. Anytime I update the state of the component, I get "unmounted" in console.log which means that updating states calls the returned function

🌐
Retool
retool.com β€Ί blog β€Ί hooks-and-state-102-the-dependency-array-in-useeffect
Retool Blog | Hooks and state 102: the Dependency array in useEffect()
July 9, 2025 - You can tell React to skip unnecessarily rerunning the effect by specifying an array of dependencies as the second argument to the useEffect call. Only if one of the dependencies has changed since the last render, will the effect be rerun. If you specify an empty array, then the effect will ...
🌐
Devtrium
devtrium.com β€Ί posts β€Ί dependency-arrays
What are dependency arrays in React? - Devtrium
August 8, 2021 - For the useEffect hook, it means running the callback. For the useCallback hook, it means changing the function being returned by the hook. Same for useMemo, but with a value. If you want more info on those hooks, reach out on Twitter to poke ...