Skip to content

Instantly share code, notes, and snippets.

@StevenJL
Last active October 1, 2018 02:57
Show Gist options
  • Save StevenJL/5e3b184a4bfb8bce24444112d1c7058a to your computer and use it in GitHub Desktop.
Save StevenJL/5e3b184a4bfb8bce24444112d1c7058a to your computer and use it in GitHub Desktop.
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