useEffect being called twice in Nextjs Typescript app

Viewed 2135

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)
  }, [])
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.

Related