chrisminnick/react-js-foundations

Chapter 06 - filteredList

Closed this issue · 1 comments

You start the section of code with a ternary on reminders -

const filteredList = reminders ? [...reminders] : undefined;
Then you then redefine filteredList with a call to the function

const filteredList = filterList(reminders, selectedFilter)

In the repo code the first definition is removed. The problem is if no reminders an error is thrown plus we are still calling to RemindersList component.

Outside of initializing reminders with an empty array (and than bypassing Proptypes defult) what can be done ?

Unless I misread something this works -
const filteredList = reminders ? filterList(reminders, selectedFilter) : undefined;

Good catch! Yeah, my first instinct was to initialize reminders with an empty array, but that defeated what I wanted to do with the default prop. Anyway, I like your solution and I'll update the repo. Thanks