Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

useEffect being called twice in Nextjs Typescript app [duplicate]

I have a simple useEffect function setup with the brackets like so:

  useEffect(() => {
    console.log('hello')
    getTransactions()
  }, [])

However when I run my app, it prints two hellos in the console. Any idea why?

Even if I add something like this, two hellos print still.

  const [useEffectCalled, setUseEffectCalled] = useState<Boolean>(false)

  useEffect(() => {
    console.log('hello')
    if (!useEffectCalled) {
      getTransactions()
    }
    setUseEffectCalled(true)
  }, [])
like image 903
cormacncheese Avatar asked Dec 20 '25 18:12

cormacncheese


1 Answers

Thanks to Joel Hager I was able to get it working by editing by next.config.js to

const nextConfig = {
  reactStrictMode: false,
};

and restarting my app.

like image 129
cormacncheese Avatar answered Dec 22 '25 07:12

cormacncheese



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!