Last active
April 28, 2016 12:55
-
-
Save erikthedeveloper/e03f2775cccfea8c7da5c6f39e95fdee to your computer and use it in GitHub Desktop.
Simple example w/ propTypes...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, {PropTypes} from 'react' | |
| const examplePropTypes = { | |
| // Require the title | |
| title: PropTypes.string.isRequired, | |
| // Optional function | |
| doThisWhenClicked: PropTypes.func, | |
| // Some array of "special things with a certain shape" | |
| specialThings: PropTypes.arrayOf( | |
| PropTypes.shape({ | |
| id: PropTypes.number.isRequired, | |
| name: PropTypes.string.isRequired, | |
| deleteMe: PropTypes.func.isRequired, | |
| specialOptionalAttribute: PropTypes.any, | |
| tags: PropTypes.arrayOf(PropTypes.string), | |
| }) | |
| ).isRequired, | |
| } | |
| const MyComponent = (props) => {/*...*/} | |
| MyComponent.propTypes = examplePropTypes | |
| const MyComponent = React.createClass({ | |
| propTypes: examplePropTypes, | |
| // ... | |
| }) | |
| class MyComponent extends React.Component {/*...*/} | |
| MyComponent.propTypes = examplePropTypes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment