PropTypes in functional stateless component

Posted by Editorial Staff | Updated on

In this example, We haves shared propTypes in functional stateless component in Reactjs. The official docs show how to do this with ES6 component classes, but the same applies for stateless functional components. Firstly, npm install to add the new prop-types package if you haven’t already.

Then, add your propTypes (and defaultProps too if required) after the stateless functional component has been defined, before you export it.

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers