Listing 6-45: Validating and Setting Defaults for FilterSelect
import PropTypes from 'prop-types';
function FilterSelect(props){
return(
<label htmlFor="filterReminders">Show tasks due:
<select id="filterReminders" value={props.selectedFilter}>
<option value="2day">within 2 Days</option>
<option value="1week">within 1 Week</option>
<option value="30days">within 30 days</option>
<option value="all">any time</option>
</select>
</label>
);
}
FilterSelect.propTypes = {
selectedFilter: PropTypes.string,
setSelectedFilter: PropTypes.func
}
FilterSelect.defaultProps = {
selectedFilter:'all'
}
export default FilterSelect;
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.