Code for Kata 3 is available in the app3 folder.
The idea here is to keep learning the concept of state
, props
, callbacks
and React lifecycles in React.
Write the JavaScript/React code to:
- Filter products by name
- Show/Hide product descriptions
- Add a
<form>
to filter products within thefilter-products
div. It should contain:label
for product nameinput
for filtering by name
- Add a handler function for the
onChange
event of the form. The function should:- save the product
name
from the event in astate
property.
- save the product
- Filter products in the
render
method based on filter input.- you could do filter with javascript array object or filter with underscore to do this.
The idea is to have products be collapsible.
- Change the
Product
component so that descriptions are not shown.- do this by checking a product state property (for example:
showDescription
) - a very common pattern in React is conditional rendering, here are some examples:
{condition? <div>foo</div>: null}
{condition? <div>foo</div>: <div>bar</div>}
{condition && <div>hello</div>}
- do this by checking a product state property (for example:
- Add a
+
or-
component next to the product name and toggle it on click- it should show or hide the product description.
- listen to
onClick
on the component you just created and update your flag accordingly.