Dpp.js
import PropTypes from 'prop-types';
//检测prop类型
class Dpp extends Component {
constructor()
{
super();
}
render() {
let {name}={...this.props}
return (
<div>
{name}
</div>
);
}
}
Dpp.propTypes={
name:PropTypes.string
};
export default Dpp;
index.js
let name=3
ReactDOM.render(<Dpp name={name}/>, document.getElementById('root'));
报错信息
Warning: Failed prop type: Invalid prop
name
of typenumber
supplied toDpp
, expectedstring
. in Dpp (at index.js:32)
网友评论