0

My alert prompt showing 2 times in React

I use this syntax

  const [namaTamu, setNamaTamu] = useState('');

  useEffect(() => {
    const handlePrompt = () => {
      const input = prompt('Masukkan nama:');
      if (input !== null) {
        setNamaTamu(input);
      } else {
        setNamaTamu("Tamu Undangan");
      }
    };

    handlePrompt();
  }, []);

Can anyone help me why my alert prompt showing 2 times? i need it just to show 1 time

  • This is likely due to StrictMode being on. See the answer to the other question. StrictMode intentionally double invokes the effect in development mode. – Marc Baumbach May 21 '23 at 22:37

0 Answers0