Listing 6-43: Adding PropTypes and Default Values to InputForm
import PropTypes from 'prop-types';
function InputForm(props){
return(
<form>
<input value={props.userInput.reminderText}
id="reminderText"
type="text"
placeholder="What do you want to do?" />
<input value={props.userInput.dueDate}
id="dueDate"
type="date" />
<button>Add Item</button>
</form>
);
}
InputForm.propTypes = {
userInput: PropTypes.shape({
reminderText: PropTypes.string,
dueDate: PropTypes.string
}),
setUserInput: PropTypes.func
}
const date = new Date();
const formattedDate = date.toISOString().substr(0,10);
InputForm.defaultProps = {
userInput: {
reminderText:"",
dueDate:formattedDate
}
}
export default InputForm;
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.