Traditionally, dealing with asynchronous code in React has required some boilerplate:
But ideally, we want:
Here, I am going to show you how to achieve just that and how to structure asynchronous code in a modern way.
We are going to use the Suspense component and Error Boundaries. They have been available since React 16.6.
The Suspense component will display a fallback
user interface until all of its children will have their state fulfilled:
<Suspense fallback="Waiting...">
<ChildComponent1 />
<ChildComponent2 />
</Suspense>
#react #promises #error-boundaries #asynchronous #suspense