DEV Community

mohammad adnan
mohammad adnan

Posted on

2

async await in useEffect

heyy guys.. after creating another project on MERN Stack i came to know that temporary way of using async await in useEffect in react were not working because of react new update and also it was not the right way to use it

this is the wrong way of using it :

Image description

So I use this right way :

Image description

Top comments (1)

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

Really? I have never seen the wrong way before. How old is that?

Anyway, did you know that now pretty much all browsers (desktop and mobile) support top-level await? This is a recent JavaScript feature that allows you to await at the top-level of your modules. If you enable this in React's Webpack configuration (use the @craco/craco NPM package or npm eject), you'll most likely find a more pleasant asynchronous programming experience.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay