Next.js Discord

Discord Forum

React. Strict Mode. Double render. Initial alert banner displayed twice

Unanswered
Virginia's Warbler posted this in #help-forum
Open in Discord
Virginia's WarblerOP
At the beginning, I need to display an alert at the beginning, hence I use useEffect.
But the Strict Mode 2x render messes that up.
I know I shouldnt rid Strict Mode.
So how can I tackle this problem.

I tried to use a flag but below didnt work
  const [checked, setChecked] = useState(false)
  useEffect(() => {
    console.log(checked);
    if (!checked)
    {
      checkForAlerts(); // Display alert banner
      setChecked(true);
    }
  }, [checked]);

3 Replies

Virginia's WarblerOP
No no, seperate question
ah ok