prototype in react js code example
Example 1: proptypes oneof
import PropTypes from 'prop-types';
MyComponent.propTypes = {
optionalArray: PropTypes.array,
optionalBool: PropTypes.bool,
optionalFunc: PropTypes.func,
optionalNumber: PropTypes.number,
optionalObject: PropTypes.object,
optionalString: PropTypes.string,
optionalSymbol: PropTypes.symbol,
optionalUnion: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.instanceOf(Message)
])
};
Example 2: react propthpes or
size: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
Example 3: react prototype function
class Foo extends Component {
handleClick() {
console.log('Clicado');
}
render() {
return <button onClick={this.handleClick.bind(this)}>Clique em mim!</button>;
}
}
Example 4: react prototype function
<button onClick={this.handleClick}>