Sass,ComonpasYeoman,Grunt,WebpackCommonJS,NodeJS<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>var Hello = React.createClass({
render: function() {
return <div>Hello {this.props.name}</div>;
//这里的节点不是dom节点
//这里的{ }指的是要取js的表达式的值
}
});
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);
react components,包括div标签,这些div标签代表的都不是dom节点,而是react components实例.
return <div className='alert-text'></div>
//在jsx中style需要用样式对象表示.在jsx中js的表达式需要用{}
//样式key使用的驼峰写法.
var style = {color:'red'}
return <div style={style}></div>
Mounted:
React Components在render解析,生成对应的DOM节点,并被插入到浏览器DOM结构的过程
Update:
一个moounted的React Components重新render的过程. DOM不一定会改变,只有react在比较了dom之后.
Unmounted
控件从对应的DOM节点移除.
hook
react对状态都封装了对应的hook函数.

Mounting
componentWillMountcomponentDidMountgetInitialState()
Updating
componentWillReceiveProps
prop时候调用,函数参数就是新的prop,可以和this.prop进行比较.shouldComponentUpdate
props和state,可以根据需要通过返回true/false来决定是否要继续.props和stateprops往往是组件的调用方在调用组件的时候指定的,指定了一般情况下修改.属于调用方.state是属于组件自己的.会根据条件修改的.state,调用组件对象的setState({});state的修改会导致组件进入updating状态.导致重新rendertip属性对组件添加名称,用于在程序中查找.React.findDOMNode,拿到domvar Hello = React.createClass({
handleClick:function(event){
var tip = this.refs.tip//拿到的是react组件
var tipEl = React.findDOMNode(this.refs.tip);//拿到真实的dom
event.stopPropagation();
event.preventDefault();
},
render:function(){
return (
<div>
<button onClick={this.handleClick}>
<span ref='tip'>
</button>
</div>
);
}
});var Hello = React.createClass({
handleClick:function(event){
this.setState({
inputContent:event.target.value
});
event.stopPropagation();
event.preventDefault();
},
render:function(){
return (
<div>
<input type='text' onChange={this.handleChange}/>
<span>{this.state.inputContent}</span>
</div>
}
});
render函数中只能有一个组件,所以多个组件需要用div等作为容器React.render(<div><Test1></Test1><Test2></Test2></div>
,document.getElementById('container'));React.createClass({});中的render函数,在return的时候也需要用div等作为容器.否则就是返回了多个组件.var Hello = React.createClass({
render:function(){
return (
<div>
</div>
);
}
});