12 Integrating data-fetching with Suspense
This chapter covers
- Wrapping promises to access their status
- Throwing promises and errors when fetching data
- Using Suspense components to specify fallback UI when loading data and images
- Fetching data and resources as early as possible
- Recovering from errors when using error boundaries
The React team have a mission to maintain and develop a product that makes it as easy as possible for developers to create great user experiences. As well as writing comprehensive documentation, providing intuitive and instructive developer tools, authoring descriptive and easily actionable error messages and ensuring incremental upgrade paths, the team want React to make it easy to provide fast loading, responsive and scalable applications. Concurrent Mode and Suspense offer ways to improve the user experience, orchestrating the loading of code and resources, enabling simpler, intentional loading states and prioritizing updates that let users get on with their work or play. But the React team don’t want hooking into Concurrent Mode to be a burden on developers; they want as many of the benefits as possible to be automatic and any new APIs to be intuitive and in-step with existing mindsets. So, Concurrent Mode is still flagged as experimental as the APIs are tested and tweaked. Hopefully, we won’t be kept in suspense for much longer! [No! We agreed, no suspense jokes – ed]