React prop-types 数据检测

npm install --save prop-types
import React from 'react';
import PropTypes from 'prop-types'; // ES6
lass MyComponent extends React.Component {
  render() {
    // ... do things with the props
  }
}
 
MyComponent.propTypes = {
  // You can declare that a prop is a specific JS primitive. By default, these
  // are all optional.
  optionalArray: PropTypes.array,
  optionalBool: PropTypes.bool,
  optionalFunc: PropTypes.func,
  optionalNumber: PropTypes.number,
  optionalObject: PropTypes.object,
  optionalString: PropTypes.string,
  optionalSymbol: PropTypes.symbol
}

猜你喜欢

转载自blog.csdn.net/weixin_41111068/article/details/88079013