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 React Basics!
You have completed React Basics!
Preview
In React, state is never modified directly. The only way React allows you to update a component's state is by using the set function returned by the useState Hook
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 next, let's update the quantity state
inside the incrementQuantity function,
0:00
so that each time a user
clicks the plus button,
0:02
the Counter's quantity increases by one.
0:06
It's important to remember that
state is never modified directly.
0:09
In other words, we can't just add
1 to the quantity state like this.
0:13
You can only change a component state
using the state setter function we
0:19
received from the useState hook.
0:24
So in our incrementQuantity, let's call
our state setter function, setQuantity.
0:26
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