react-PropTypes

//Component1.jsx
import React from 'react';

var arr = [
  <h1>Hello world!</h1>,
  <h2>React is awesome!</h2>,
];

class Component1 extends React.Component {
    render() {
        const propTypes={
            title: React.PropTypes.string.isRequired,
        };
        return <h1> {this.props.title} </h1>;
    }
}

//导出组件
export default Component1;
//main.js
import React from 'react';
import ReactDom from 'react-dom';
import Component1 from './components/Component1.jsx';

var data=123;
ReactDom.render(
     <Component1 title={data} />,
    document.getElementById('content')
);
  1. const propTypes={
    title: React.PropTypes.string.isRequired,
    };没有起作用

  2. 输出结果:123

posted @ 2017-04-07 16:21  sakura-sakura  阅读(131)  评论(0编辑  收藏  举报