Skip to content

Instantly share code, notes, and snippets.

@lokhmakov
Created March 25, 2017 11:03
Show Gist options
  • Save lokhmakov/61b659ed75119141ba27ccb9aadf3a69 to your computer and use it in GitHub Desktop.
Save lokhmakov/61b659ed75119141ba27ccb9aadf3a69 to your computer and use it in GitHub Desktop.
snippet - propTypes.isDefined
import React, { PropTypes } from 'react'
const isDefined = (props, propName, componentName) => typeof props[propName] === 'undefined' && new Error('${ propName } undefined')
class YourComponent extends React.Component {
static propTypes = {
id: isDefined
}
render() {
const { id } = this.props
return (
<div>
{ id === null ? 'NULL' : id }
</div>
)
}
}
export default YourComponent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment