Last active
October 1, 2018 02:57
-
-
Save StevenJL/5e3b184a4bfb8bce24444112d1c7058a to your computer and use it in GitHub Desktop.
This file contains hidden or 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'; | |
class ItemComponent extends React.Component { | |
// propTypes can be defined inside the Component definition | |
static propTypes = { | |
name: PropTypes.string.isRequired, | |
price: PropTypes.number.isRequired, | |
purchaseHandler: PropTypes.func.isRequired | |
}; | |
render() { | |
return( | |
<div> | |
div> Item:{name} </div> | |
div> Price:${price} </div> | |
<button onClick={purchaseHandler}> Purchase </button> | |
</div> | |
) | |
} | |
} | |
// propTypes can also be defined outside the Component | |
ItemDiv.propTypes = { | |
name: PropTypes.string.isRequired, | |
price: PropTypes.number.isRequired, | |
purchaseHandler: PropTypes.func.isRequired | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment