And this example, and let me actually refresh so that the JavaScript disappears. So this example is essentially the same example, right? I can click on it and run. And as you can see, the JavaScript shows up when I hover over it. The question is how is this different? So let's have a look.
So okay. So the difference I'm gonna make here is what I've done is I've built the counter, but notice I moved the state outside of the component. Right, this is typical of what you would do, like when you have a component that, let's say a shopping cart and a shopping cart and an add to shopping cart button, you put the state in the least common parent, right? And so in this case, what I have is I have two components, display and incrementor. And display just shows the count and the incrementor just increments, you know, calls the callback button basically, is just a glorified button. And I move the state into the parent, which this happens to be a quick component. And by passing the state into, by having the state at the parent, now I can pass the state both to a display and I can pass a callback to the incrementor, right? And so in this way, I can have the incrementor talk to each other. And so what I wanna show you is no JavaScript is present over here, right? When I hover over this button, right, the JavaScript for the button shows up. So at this point, we woke up the component and hydrated the button itself only. So let me clear this for a second, so you can see. Now if I hit plus one, what we downloaded was just a piece of code that was the callback, just the count plus plus, right? So we downloaded this callback and nothing else, right? So just this callback downloaded. But once we modified the display, right, so once this signal modified, the system was like, hey, this signal is being passed to the display. And so as a result, we now have to also wake up the display. And so the second file that downloaded over here is the display, and this is just the React code for the display that gets hydrated and re-rendered, etc so that the count gets to update. And so what I really wanna show you is these inter-island communication. And I think this is the key, right? Without inter-island communication, the islands are really not that useful.
Okay, so let's do something more fun. So here is a slider component. Here, let me refresh the UI again. And so let's look at a slider. Slider. Okay, so what I did with the slider is notice I just took a material UI, as an existing library that's super popular at Qwik, React, and I wrapped it in a Quickify, and I specified the rules under which it should be hydrated. So I simply said, you know, when somebody hovers over this particular thing, I want you to hydrate it. Or there's other rules. You can say, you can do a specific event, like I'm scroll, or you can say I'm visible, or something like that, but let's just do hover for our purposes. And so taking this Quickify component, I can drop it in here. And I can also have a regular input, which is a standard HTML component.
Comments