0

import { useEffect, useRef } from "react";
import "./styles.css";


export default function App() {

  const refdata = useRef();

  useEffect(()=>{
    console.log("sam");
  },[refdata])

  return (
    <div className="App">
      
    </div>
  );
}

output : I see two time sam in console. I don't understand why console.log run twice. please help me to understand this

Samruddh Shah
  • 41
  • 2
  • 5
  • 1
    It is not dependent on `useRef`. Any `useEffect` with a dependency(s) runs twice: first at the initial render, then when a dependency changes – ABDULLOKH MUKHAMMADJONOV Apr 02 '22 at 07:20
  • Does this answer your question? [React 18, useEffect is getting called two times on mount](https://stackoverflow.com/questions/72238175/react-18-useeffect-is-getting-called-two-times-on-mount) – Youssouf Oumar Sep 21 '22 at 16:00

0 Answers0