React组件渲染和更新的实现代码示例-创新互联
最近一直写React,慢慢就对里面的一些实现很好奇。最好奇的就是自定义标签的实现和this.setState的实现。这里不分析JSX是如何解析的,所有组件都用ES5方式编写。

组件渲染
渲染时候,我们会调用render方法。类似下面这样:
var SayHi = React.createClass({
getInitialState: function() {
return {verb: 'say:'};
},
componentWillMount: function() {
console.log('I will mount');
},
componentDidMount: function() {
console.log('I have mounted');
},
render: function() {
return React.createElement("div", null,this.state.verb, "Hello ", this.props.name);
}
});
React.render(React.createElement(SayHi, {name: "Cynthia"}), document.getElementById("container")); 新闻标题:React组件渲染和更新的实现代码示例-创新互联
URL标题:http://www.jxjierui.cn/article/dhodhc.html


咨询
建站咨询
