From the course: React Hooks

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Sending interactions up component trees

Sending interactions up component trees - React.js Tutorial

From the course: React Hooks

Start my 1-month free trial

Sending interactions up component trees

- [Instructor] We've used React properties to get us this far, we've created a few different stars. Now, what we need to do is we need to handle clicking on them. In order to do this, we're going to create a state variable using useState. So we're still importing useState from React. And then if I scroll down a little bit to our star rating component, this is where I'm going to manage the state. So first we're going to create a constant here. We'll call this selectedStars and setSelectedStars. Those are long variable names, but they're descriptive so we'll stick with that. Or as an initial state we want to provide zero. So we'll say that when our component renders we don't want to have any of these be selected. Now we need to supply these properties to each one of the stars 'cause the star is actually the component that's being clicked. We want to make sure it has access to this state variable. So I can pass to…

Contents