It is time to learn how to deal with components that do fetch requests.
Important: Accessing the code
If you're not following the course from the start or you just want to access the code from the beginning of this module, it is available in the
module-03-beginbranch in your repo, and you can also find it in the same branch at the Storybook for react apps template repo.
In the previous module, we saw the development process of an entire feature, the
RestaurantsSection component. Although we managed to develop and add it to Storybook, that feature does data fetching, so the stories are fetching data from the real endpoint in Storybook. You can notice that when opening the stories and checking the network tab in the dev tools panel:
Given that we want fixed states of our components in Storybook, it's not ideal to rely on real data fetching. It could be that the requests take a long time, are flaky, or the services are either broken or unavailable, making our stories unreliable. That's not something we want! In Storybook, we want predictability and the ability to work offline, having ways to build UI independently from the backend.