Current section: Custom Components 59 exercises
Problem

Simple Function

Loading exercise

Transcript

00:00 For this first part of the exercise, we're going to get ourselves a little bit closer to having some generic function that can generate some JSX that's reusable. So here we've got our container. We've got two messages, hello world and goodbye world. And there's some duplication there that we might want to reduce.

00:19 And so here's what it would look like if it was a little more generic. So it's got a class name message, but it also has this dynamic children. And so what if we made a function called message that allowed us to pass those children, right? That could be useful, especially if this was a lot more complicated and we wanted to reuse it all over the place.

00:39 And so your objective is to do pretty much exactly this, make this API work. This is not a React component, or at least it's not used in the way React components are intended to be used. But this will get us a little bit closer to the point where we can actually do this. And again, this only works because of interpolation. We're interpolating a function call,

00:58 which is an expression into this position. And the result of that function call will be React elements. So that just, that works out nicely because the div children can take React elements. So have a good time with this one. We'll see you when you're finished.