Code for Kata 2 is available in the app2 folder.
The idea here is understand the concept of a state
and callbacks in a React component.
How state
works and how to modify it.
Write the JavaScript/React code to:
- Add new products to the listed products
- Be able to remove products from the list of products
- Move the
data.products
passed to the<Products>
component to astate
property inApp.js
and passthis.state.products
to<Products>
instead - Add a
<form>
to add new products within theadd-product
div. It should contain:label
for product nameinput
for product namelabel
for descriptioninput
for description- a submit button
- Add a handler function for the
onSubmit
event of the form. The function should:- get
name
anddescription
from the event - update the products array in the state with a new product. (Using State Correctly)
- keep in mind that State Updates are Merged
- Forms
- Handling Events
- get
- Add a function to remove a product in
App.js
- Make the remove product function available to use in all
<Product>
components and use it when the div with theremove
class is clicked. - Test that you can add products and remove them from the app.