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')
);
-
const propTypes={
title: React.PropTypes.string.isRequired,
};没有起作用 -
输出结果:123