react-container
Goals
Create a
SearchBox
component to list only robots that match the search termKey inputs are handled by
SearchBox
, but robots are being provided by parent componentWe need some way to integrate the two
Solution:
Make the search box and display stateless (display) components
Use the parent as a common third party to hold the data
Main Application
How It Works
Note how
onSearchChange
is passed down toSearchBox
Remember, every
setState
call triggers re-renderingSearchBox
doesn't need to care whose state it is updating
Also note how
filteredRobots
is set by filtering entire robot listDo not modify the main list, since we don't want to throw robots away
Again,
CardList
doesn't care which list it is displaying
Search Box
In principle, this is re-rendered on each keystroke because of the parent's state change
React does work behind the scenes to minimize work
Last updated
Was this helpful?