Answers for "proptypes and default props property"

3

proptypes array of objects

MyComponent.propTypes = {
  items: PropTypes.arrayOf(
    PropTypes.shape({
      code: PropTypes.string,
      id: PropTypes.number,
    })
  ),
};
Posted by: Guest on September-03-2020
14

default props react

// ES6 class
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"
}
Posted by: Guest on April-05-2020

Code answers related to "proptypes and default props property"

Browse Popular Code Answers by Language