var List = React.createClass({
getInitialState: function(){
return['a','b','c']
},
render: function(){
return(...);
}
});
import React from 'react';
class List extends React.components{
constructor(){
super();
this.state = ['a','b','c'];
}
render(){
return(...);
}
}
import React from 'react';
import ReactDOM from 'react-dom';
export default class CompomentHeader extends React.Component{
render(){
return(
<header>
<h1>这里是表头</h1>
</header>
);
}
}
var React = require('react');
var ReactDOM = require('react-dom');
import CompomentHeader from './components/header';
class Index extends React.Component {
render() {
return (
<div>
<CompomentHeader/>
<h1>页面主题内容</h1>
</div>
);
}
}
// 入口
ReactDOM.render( < Index / > , document.getElementById('example'));
import React from 'react';
//当一个标签里面为空的时候,可以直接使用自闭和标签
//注意class是一个JavaScript保留字,所以如果class应该替换成className
let divElement = <div className="foo"/>;
//等同于
let divElement = React.createElement('div',{className:'foo'});
import React from 'react';
class Headline extends React.component{
...
render(){
//直接return JSX语法
return <h1>Hello React</h1>
}
}
let Headline = <Headline />;
let headline = React.createElement(Headline);