♪♪♪ Had to make a quick correction. He didn't read the copyright. I'm the second-best TypeScript YouTuber. Just wanted to clarify. Not gonna steal valor from Matt Pelcock. He's very good at what he does.
But for those who don't know me, I'm Theo. I've been doing software dev videos for about two years now. And who's watched one of my videos before? Yeah! Woo! Decent number of y'all. Good stuff. I don't know why.
So, I'm giving my talk today about streaming and not just in React, but as a whole why it's cool and the benefits of adding streaming to your applications. And I'm doing that, first and foremost, by showing you a normal React app written the way many of us have written it before. I just refresh the page, we see the loading, and we have our signed-in state. We've all hopefully written code like this before. Maybe not, actually. Let's see.
Who's written code like this before? Let's see hands. I can't actually see the hands because I literally just have a black box here, but I trust there's a decent number of them. If you've written code like this, move to React Query.
Anyways, this code works fine. The page loads, it has a JavaScript tag in it, the browser loads the JavaScript tag, the JavaScript parses, renders the component, realizes, oh, I need to go fetch this data. And it then goes and makes the API request, gets the data, sets it a state, and then re-renders with the new updated state. There are a couple problems here, though. Obviously, there are race conditions and whatnot. We're going to ignore those. The main problem is that I have to wait until the page has loaded the HTML, fetch the JavaScript, parse the JavaScript, run the JavaScript, render the component, and then we can finally start the fetch when we could have been doing all of that work during that time before. How, though? Because we need to have this content on the page. We can't just send some HTML and send the rest later. Or can we? There is this wonderful little demo that Guillermo tweeted a while back.
Comments