Reputation: 1168
I am testing ReactJS. Everything is working properly but React.PropTypes. here is the code:
const MenuItem = (props) => {
return (
<li className="list-group-item">
<span className="badge">{props.price}</span>
<p>{props.item}</p>
</li>
)
}
MenuItem.propTypes = {
price: React.PropTypes.number
};
When I send string to the component there isn't any warning or errors. Not different which PropTypes I use.
What is my mistake? Thanks a lot
Edit: It's not working even I use PropTypes with React.Component!
Upvotes: 2
Views: 2620
Reputation: 4228
propType warnings aren't showing in the console because you're using the production build of React. They only show in dev mode (the un-minified React export).
To be clear, this is not an issue with Functional Components - propTypes can be set on them as they are in the question.
Upvotes: 4
Reputation: 4945
If you are going to use class properties you should probably use a class.
class MenuItem extends React.Component {...}
See https://facebook.github.io/react/docs/react-component.html.
Upvotes: 0