0

For some reason with this code the alert is displayed twice. Why is this? All people with similar issues seem to be using React in strict mode. How do I turn off strict mode if its somehow on by default for me. And if that's not the issue, what is?

    import React from "react";
import { createRoot } from 'react-dom/client';
import { BrowserRouter, Routes, Route, Link } from "react-router-dom";

import { useState, useEffect } from "react";
import ReactDOM from "react-dom/client";




function Main()
{
    const [count, setCount] = useState(20);

    //setInterval(setCount(count - 1), 1000);

     useEffect(() => {
    setTimeout(() => {
      setCount((count) => count > 0 ? count - 1 : alert("boom"));
    }, 1000);
  });
    return(
<div> {count} </div>
)
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Main />);
DennisM
  • 359
  • 1
  • 3
  • 13
  • Does this answer your question? [Why useEffect running twice and how to handle it well in React?](https://stackoverflow.com/questions/72238175/why-useeffect-running-twice-and-how-to-handle-it-well-in-react) – Youssouf Oumar Dec 10 '22 at 16:52

0 Answers0