mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
Exercise
TodoFooter
- Open TodoFooter and write a TodoFooterProps interface. It should include two values, a function and an object. Assign this interface to props like this:
(props: TodoFooterProps) - Write an
_onClickfunction that callsprops.clear.Since TodoFooter is not a class the
_onClickneeds to be declared as a const, and placed before thereturn. - Add
_onClickto the button'sonClick. You won't need to usethissince this isn't a class.We can't assign our
clearfunction directly toonClick. We always need to create a function that calls our callbacks.() => props.clear() - Test out this functionality. Check a few todos complete and click the
Clear Completedbutton
TodoHeader
- Open TodoHeader and write TodoHeaderProps which will include 3 values. Replace the first
anywith this interface. - This component also has state. Write TodoHeaderState (there's just one item), and add this where the second
anywas. - Add
_onFilterto each of the filter buttonsNote that we can't add new parameters to onClick, but we can pull information from the event target!
- Write an
_onAddmethod that callsaddTodoon the currentlabelInput, then sets thelabelInputin state to an empty string - Call
_onAddfrom the submit button - Check out this new functionality! We can now add and filter todos!