How to use async function in React hooks useEffect (Typescript/JS)?

added by JavaScript Kicks
10/21/2019 9:56:01 AM

2665 Views

👾At first glance you could have the idea to do something similar to get your content from a remote API as example. const MyFunctionnalComponent: React.FC = (props) => { useEffect(async () => { await loadContent(); }, []); If you're using Typescript, the compiler should be yielding something like this : Argument of type '() => Promise ' is not assignable to parameter of type 'EffectCallback'.


0 comments