Code Editor

Remember stateless functional components? You can see some familiar ones in Example.js.

How could you write propTypes for a stateless functional component?

You couldn't do it in the usual way! The usual way involves adding a propTypes property to the instructions object. Stateless functional components don't have instructions objects:

// Usual way: var Example = React.createClass({ propTypes: { isExample: true }, ... // Stateless functional component way: function Example (props) { // ummm ??????

To write propTypes for a stateless functional component, you define a propTypes object, as a property of the stateless functional component itself. Here's what that looks like:

function Example (props) { return <h1>{props.message}</h1>; } Example.propTypes = { message: React.PropTypes.string.isRequired };
Report a Bug
If you see a bug or any other issue with this page, please report it here.