Type checking a Component's Props - KatyaHorton/Udacity-React-practice GitHub Wiki
PropsTypes
Type checking a Component's Props with PropTypes is a package which helps us to avoid unintended (unexpected) data types, in our app, as it becomes bigger.
To install:
npm install --save prop-types
Like if we accidentally pass an object, where array is expected, etc.
With PropTypes we can specify (if we wish so) the specific properties that we are passing into a component to be required (or not).
ListContacts.js
example:
Our //imports PropTypes from the package we insatalled
import PropTypes from 'prop-types'
...
ListContacts.proptypes = {
contacts: PropTypes.array.isRequired,
onDeletecontact:PropTypes.func.isRequired
}
Adds a property to our component, setting the value of
contacts
to an arrayonDeleteContact
to a function, both PropTypes are required ;)