React(PropTypes)

Dpp.js

import PropTypes from 'prop-types';

//检测prop类型
class Dpp extends Component {
    constructor()
    {
        super();
    }

    render() {
        let {name}={...this.props}
        return (
            
{name}
); } } Dpp.propTypes={ name:PropTypes.string }; export default Dpp;

index.js

let name=3
ReactDOM.render(, document.getElementById('root'));

报错信息

Warning: Failed prop type: Invalid prop name of type number supplied to Dpp, expected string. in Dpp (at index.js:32)

你可能感兴趣的:(React(PropTypes))