Async functions with React's useEffect hook
It may not be pretty, but the easiest way to call an async function in useEffect is to use an Immediately Invoked Function Expression (IIFE).
useEffect(() => {
(async () => {
try {
await doSomething();
} catch (err) {
console.error(err);
}
})();
}, []);
That's it! Don't overthink it.
Table of Contents
Building an MVP?
I partner with founders to turn your vision into a product that ships.
Strategy, architecture, and hands-on development from someone who has led 50+ product launches.
Let's talk about your MVP