您不需要其他库,“ prop-
types”提供了现成的功能。参见https://facebook.github.io/react/docs/typechecking-with-
proptypes.html
例:
import PropTypes from 'prop-types';//.......ExampleComponent.propTypes = { showDelete: PropTypes.bool, handleDelete: function(props, propName, componentName) { if ((props['showDelete'] == true && (props[propName] == undefined || typeof(props[propName]) != 'function'))) { return new Error('Please provide a handleDelete function!'); } },}


