Current section: Sync External State 36 exercises
solution

Make Store Utility

Loading solution

Transcript

00:00 If I'm being honest, this is a bit of a like regular JavaScript refactor So you might be like wait, why is he having us do this, but it will turn out to something interesting I promise in the next step. So let's make our function make media query store this is going to take a media query, which is a string and we're going to take all this stuff yoink and

00:20 Stick it right in there. And then we're going to return a hook Called use media query, which will return use sync external store with subscribe and snapshot Hmm, that's interesting. Okay, and then we can make a

00:38 Call to that here const use narrow media query call it with this and Now we can just call use narrow media query Instead of you sync external store, so we've got like this really nice API for

00:56 Making any media query store that we want to and hopefully it still works. Yep wide narrow wide narrow So good stuff. We're in a good spot there. And now we have this reusable utility that encapsulates the The hook for us so we don't have to worry about it

01:14 Yeah, and it's kind of cool to dynamically create hooks like that. So there you go. Hope you had a good time And I'll see you in the next video. Bye