defaultprops in react code example
Example 1: default props react
class CatComponent extends React.Component {
constructor(props) {}
render() {
return <div>{this.props.catName} Cat,
Eye Color: {this.props.eyeColor },
Age: {this.props.age}</div>
}
}
CatComponent.defaultProps = {
catName: "Sandy",
eyeColor: "deepblue",
age: "120"
}
Example 2: react proptypes example
Detaljer.PropTypes = {
detaljer: PropTypes.string.isRequired,
feilkode: PropTypes.string,
removeEvent: PropTypes.string.isRequired
};
Detaljer.propTypes = {
detaljer: PropTypes.string.isRequired,
feilkode: PropTypes.string,
removeEvent: PropTypes.string.isRequired
};
Example 3: defaultProps in react
defaultProps in react