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 this video, we'll use the filter() array iteration method to remove an object from the items array in state.
Treehouse Courses & Workshops
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
Within the app component, we'll create a
new arrow function named handleRemoveItem.
0:00
This function will take an id parameter,
0:02
which will specify the item
to be removed from the state.
0:05
Then call the setItems function
we received from useState.
0:09
Remember, it's important not to
directly modify or mutate the state.
0:14
Instead, we'll construct
a new array that no longer
0:19
contains the item object
we want to remove.
0:24
There are several ways to achieve this,
but a common and
0:28
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