Props validation
"React provides a way to validate the props using PropTypes. This is extremely useful to ensure that the components are used correctly. Here is an example of using propTypes
for our app." explained Mike.
var App = React.createClass({ propTypes: { headings: React.PropTypes.array, changeSets: React.PropTypes.array, author: React.PropTypes.string.isRequired }, render: function(){ return(<table className = 'table'> <Headings headings = {this.props.headings} /> <Rows changeSets = {this.props.changeSets} /> </table>); } });
"Oh! Will it show an error as we are not passing the author, which is required, I assume? I see that propTypes
has set the author value to be isRequired
." Shawn asked.
"No. It will not throw an error, but it will show a nice warning for us to take a look at." said Mike.
"Also, propTypes
are only checked in development. Their job...