Skip to content

Instantly share code, notes, and snippets.

@adhithiravi
Last active May 23, 2018 21:03
Show Gist options
  • Save adhithiravi/c289cbb88a3eb5e6b6d62ac3fc4fadce to your computer and use it in GitHub Desktop.
Save adhithiravi/c289cbb88a3eb5e6b6d62ac3fc4fadce to your computer and use it in GitHub Desktop.
Showing use of defaultProps
import PropTypes from 'prop-types'
export default class MyComponent extends React.Component {
render() {
// Render Something
}
}
// You can declare that a prop is a specific JS type.
MyComponent.propTypes = {
text: PropTypes.string,
content: PropTypes.array,
onPress: PropTypes.func,
size: PropTypes.number,
styles: PropTypes.object,
isReady: PropTypes.bool,
}
// Default values for props
MyComponent.defaultProps = {
text: 'Sample Deafult Text',
content: [],
size: 0,
onPress: () => {},
isReady: false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment