Created
March 25, 2017 11:03
-
-
Save lokhmakov/61b659ed75119141ba27ccb9aadf3a69 to your computer and use it in GitHub Desktop.
snippet - propTypes.isDefined
This file contains 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 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