Hi, everyone. I'm Charlotte. I'm a React Native Tech Lead at VAM, and I'm super excited to be back here with you today.
Today we're going to talk about a very special component, suspense. You know why suspense? You know why it's such a powerful tool? You know why we love them? But do you know how suspense works? How does suspense know a request is going to happen in my children? I should display a letter instead.
Today we're going to dive deep into the suspense component, and as we do this, we're going to learn more about React as well. So this won't be a talk about concurrency. We're going to solely focus on this component. But before we dive into the how of suspense, let me recap the why. Why do we love suspense so much?
Before suspense, our components used to look like this. We fetched some data, displayed a loader while it was loading, an error if we had to, and finally we reached to the part that's really the most interesting one about our components, the one where we really bring value to the user. With suspense, our components now look like this. We fetch some data, and we can directly use it. We don't have to bother with this loader and error edge cases anymore. They are handled above. Above our components, we define this suspense boundary that handles the loader, and this error boundary that handles the error. This way, in our components, we can directly use our data. This is why we love suspense so much. No more loaders, no more errors spread throughout all of our components. We can directly get to the data.
Now let's get into the how. For the how, we're going to need to dive deep into React. Before this, let me give you a quick reminder of how React works. React has a few fundamental roles. One of them is this one. React calls components and hooks. This means that React decides when it wants to render your components. You don't. When we call our components, we do it this way, with this JSX syntax, but calling a component this way does not mean that it will be executed right away, at least not right away. When we instantiate a component like this, with this JSX syntax, JSX is actually just syntactic sugar, and is equivalent to the call of this JSX function.
Comments