In this lab, you'll use PropTypes declaration in a variety of scenarios.
Welcome to your first day at... Dunder Mifflin! Your job is to make sure the company's products are catalogued on the website. Since we like to be modern, we'll use React to display the product information. Since our database is pretty old, we'll be sure to add PropTypes to our component so that we know we're passing in the right props.
- In the
components/Product.js
file, create aProduct
React component. - This component has the following props:
name
: a string — requiredproducer
: a string — optionalhasWatermark
: a boolean — optional, defaults to falsecolor
: a string — required, can only be'white'
,'eggshell-white'
or'salmon'
weight
: a number — required, ranges between 80 and 300
- Note: for the
weight
prop, we'll need custom logic. Remember that it's possible to write your own prop validator function!
Note: This lab might require you to restart the test watcher after changing your code.