This is a very strange lesson where it is currently placed. We have not previously used loading, server actions or server components. Theoretically, we don’t even know much about servers at this point, except that we can fetch data from them. Suddenly, useOptimistic is some sort of hook that solves some problems with these things that we have not had a chance to run into yet. Are you sure this lesson is where it should be?
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Working with Data Fetching and Memoization in React - What Is the useOptimistic Hook, and How Does It Work?
API calls have been introduced in the JavaScript section, and this page is all about how the frontend can deal with API calls, it does not seem to be in the wrong place
Yes, we did encounter fetching but, for example, we have not had to deal with loading explicitly before.
At first glance, it might seem like the useOptimistic hook is just another way to handle loading states in React. But it’s more than that.
This will definitely not seem like just another way to handle something we have not handled before. It’s the very next paragraph that teaches us what a loading state even is!
A loading state controls whether you see a spinner, message, or some other indicator in the UI while something happens in the background.
It might be useful to run into some problems with loading and handling state changes from overlapping requests first and then learn how to deal with them with useOptimistic and useTransition / startTransition.