React(PropTypes)

2017-10-26  本文已影响8人  余生筑

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 type number supplied to Dpp, expected string. in Dpp (at index.js:32)

上一篇下一篇

猜你喜欢

热点阅读