Current section: Compound Components 30 exercises
Problem

Compound Components Validation

Loading exercise

Transcript

00:00 So earlier, we told TypeScript to shut its face by adding that bang at the end of a couple places, that exclamation point. And now TypeScript is laughing its face off at us because we ignored something that was actually really important.

00:15 So if I update our app TSX file to just render the toggle button, take a look at what happens. Hmm, what is going on there? That's not good. I do not like this. Let's go over to our console and see what is going on.

00:32 Cannot destructure property on of zero comma import React use as it is null. Huh, well, that's kind of annoying. We could click on this and look. Oh, there it is, use toggle contact bang. Yikes, we cannot destructure because we have no provider.

00:51 Ah, so this is actually like, I wouldn't say this is terribly common with compound components. People are typically going to render the root one, but if they forget, wouldn't it be nice if they had a nicer error message? And that's what you're gonna be doing in this exercise, giving people a nicer error message when they make a mistake like this.

01:10 So, and on top of that, we can get rid of the exclamation point because we're gonna handle that properly, so let's get to it.