Listing 6-44: RemindersList with Default Props and PropTypes
import PropTypes from 'prop-types';
import Reminder from './Reminder';
function RemindersList(props){
const reminders = props.reminders.map((reminder,index)=>{
return (<Reminder reminderText={reminder.reminderText}
dueDate={reminder.dueDate}
isComplete={reminder.isComplete}
id={index}
key={index} />);
});
return(
<div>
{reminders}
</div>
);
}
RemindersList.propTypes = {
reminders: PropTypes.array
}
const date = new Date();
const formattedDate = date.toISOString().substr(0,10);
RemindersList.defaultProps = {
reminders: [{
reminderText:"No Reminders Yet",
dueDate:formattedDate,
isComplete: false
}]
}
export default RemindersList;
Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.
ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.