Okay, so I just stole it from here. So what we're going to do real quick is fetch data three ways. We'll do it the way we all know first, so our app. So we have a React app using Create Root, it's a new thing. We have our app component that renders, as you can see, the actual elements here, the heading, the jokes, and so on. And lastly, we have a jokes component, this thing, which is supposed to fetch data, but doesn't. So we'll fetch data three ways and then we'll talk about what we learn.
To do that, I'm going to get my data from here and fetch it immediately. Again, inshallah, network, please. Awesome, that's enough. I think, you know what I think? I think the network depends on... Okay, nevermind. I was gonna do something awesome, but now you don't.
Okay, so I'm gonna get a code snippet here in JavaScript to fetch this in my app, just client-side, as you know. So we'll do something like this. And when search changes, just refetch. We'll paste the code snippet. I'll add a filter, just for fun, where the joke contains search. And then instead of console logging the response, I will set joke to result.records, okay? I'm just fetching data. You're familiar with this. I'm not spending too much time on this. And just like that, we have jokes from an API. So what is the most used language in programming? Profanity. Ha ha, it's actually funny. Does the search work? I can use words like okay feenot. But okay, married, life of developer, wife right, 100%. So we're fetching, we're rendering the component, then fetching. This is fairly common. If we walk through the code briefly, we have the jokes in state, we fetch, and we set state, and then everyone's happy. Notice, we're not handling loading states yet.
Comments