I usually take care of any promises or asynchronous operations in the componentDidMount
or componentWillMount
lifecycle methods, but now I am using only functional components.
So I have something like this:
export async function MyComponent () {
const data = await myPromiseFunction()
return (
<>
DO SOMETHING!
</>
)
}
This obviously cannot be done because we are returning a promise when using MyComponent
. So my question becomes how can I do asynchronous operations within the functional component?
Do I just have to accept that they have to be done elsewhere and receive my necessary data as props? Or is there a cleaner way to get around this?