Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice State in React!
You have completed Practice State in React!
Preview
This video covers one way to update the courseRating state based on the star a user clicks.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
So first, I will initialize a courseRating
state here in the StarRating component and
0:00
set it to 0 by default, and
import the useState hook up top.
0:07
All right, now I'm going to write
the event handler that updates
0:15
the courseRating state based on the star,
a user clicks.
0:20
I'll call this function, handleSetRating.
0:25
And it will take the parameter rating for
the rating value.
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up