0
    I am using "react": "^17.0.2",
    
    my API call runs twice when I use useEffect on a modal popup
    
     useEffect(() => {
            console.log('kbghjdfhgd');
        }, []);
    
    when I used it in modal pop up it ran twice but if I used it in an app.js it ran once only


I am new to react not sure what went wrong in it.

  • Seems like the StrictMode thing, to help finding accidental impurities in dev mode React calls component function twice – KcH Nov 10 '22 at 11:55

1 Answers1

0

Check if you are running your project in strict mode. You can do this by checking the render() method in index.tsx.

If you don't know what 'strict mode' is here's what the React documentation says about Strict Mode

Here's how to Disable it

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 14 '22 at 15:47