Skip to content

Instantly share code, notes, and snippets.

@erikthedeveloper
Last active April 28, 2016 12:55
Show Gist options
  • Select an option

  • Save erikthedeveloper/e03f2775cccfea8c7da5c6f39e95fdee to your computer and use it in GitHub Desktop.

Select an option

Save erikthedeveloper/e03f2775cccfea8c7da5c6f39e95fdee to your computer and use it in GitHub Desktop.
Simple example w/ propTypes...
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