EDIT: Solved! I was using the production CDN for react, but I needed the development CDN. Here it is: https://unpkg.com/react@16.2.0/umd/react.development.js
I’m learning to test prop types in React and this Error should print to the console. Why isn’t it working?
It works in this tutorial around the 00:54 mark.
Here’s the code:
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">
function SayHello(props) {
return (
<div>
Hello {props.firstName} {props.lastName}!
</div>
)
}
SayHello.propTypes = {
firstName(props, propName, componentName) {
if (typeof props[propName] !== 'string') {
console.log('does it work?')
return new Error(
`Hey, you should pass a string for ${propName} in ${componentName} but you passed a ${typeof props[propName]}!`
)
}
},
}
ReactDOM.render(
<SayHello firstName={true} />,
document.getElementById('root')
)
</script>