Last active
May 23, 2018 21:03
-
-
Save adhithiravi/c289cbb88a3eb5e6b6d62ac3fc4fadce to your computer and use it in GitHub Desktop.
Showing use of defaultProps
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 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