I don't care how React handles it. I know I can do this batching operation, this sorting operation, you know, these set of things that I need before rendering without asking React to re-render my component four, five, six times. I was going to say, it's quite a common ‑‑ I wonder whether or not it's depending on which ‑‑ where your experience lies. It depends if you end up working with React or against React or working with JavaScript or against JavaScript.
Can you rephrase it again? Oh, you're talking about using the inbuilt method within the browser. Yep. Just relying on the browser, because it doesn't change. By the way, if anyone wants to add any questions, if you've got the Slido app, because I know a lot of people have downloaded Slido for various town halls or events that you've been using, if you use the code, I think it's 2010, you'll be able to jump into the session, choose the track, and add your question to the list here. So if any are kind of coming up that you think, I actually think I want to ask that for my work right now, that's a good way to kind of enter the queue.
So we've got up here next, we've got, how does the event loop handle error handling and the propagation in JavaScript applications? Well, effectively, there is no difference between how you actually handle a try-catch mechanism, an error handling mechanism. Because as we said before, we are going on the ground, on the event loop, normal way of working. So if you have a promise, you still can use the catch for error handling, there is nothing particular around how to use the queue microtask. You can still use a try-catch, you can use a sink away. You can also, even if it's not recommended, you can also have an async function being called in the queue microtask callback function. And as I said before, I would not recommend it because some browsers like Chrome can detect it and move it into the microtask queue to prevent the main thread from being blocked from a too hard call on the async.
I think you've almost inadvertently answered our next question that we've highlighted here. The answer is that we shouldn't, in general that we shouldn't use microtasks as it can be abused and cause performance issues on client's computers. Yeah, that's true, but it's also true that you shouldn't have five use effects for six set states that re-renders the page five times. So, you have to be aware at least of how you are leveraging the event loop and know that there is the microtask queue that of course can be abused. But if you know what you are doing, I think you are safe. So I think that's the point of my talk, if you know what you are doing, I think you are safe. Nice, I think we might have time for just one or two more questions. I think the next ones are kind of, the next two here, we've got can you apply this to React context and will it work in React function, so I think they're kind of asking a similar bit of context there. As I said, the best use case I find is to prevent relying on all these affect state callback. Okay. So this is the most common use case I see for the Microtask. Where you can effectively prevent the page from re-rendering in a useless way because it's going to re-render three, four, five times. Yeah. So that's the main use case I see at a glance for React. I wonder whether or not we should...
Comments