Yuanyan
Links: https://www.zhihu.com/question/27602269/answer/40168594
Source: Know
Copyright belongs to the author, please contact the author for authorization.
The use of the three is slightly different, according to the Order of dependency adjustment:
1. Createclass, as its name is the class that creates the react component, describes the various behaviors you will create for the component, where the render interface of the content that needs to be output when the component is rendered must be implemented, and the others are optional:
var Hello = React.createClass({
render: function() {
return <div>Hello Taobao, Hello UED</div>;
}
});
2. createelement, create react component instance, support Type,config,children three parameters:
ReactElement.createElement = function(type, config, children) {
...
}
As we described in jsx < hello/>, compiled is react.createelement (hello)
3. Createfactory, the factory method is used to create the react component instance, in JS to implement the factory method only need to create a createelement with the type parameter of the binding function:
ReactElement.createFactory = function(type) {
var factory = ReactElement.createElement.bind(null, type);
return factory;
};
The purpose of creating a pattern is to isolate and simplify the process of creating components, and the patterns of things are naturally unavailable, and if you need to create a component in bulk, you can do so through the factory method:
var h = React.createFactory(Hello);
h({x:1})
h({x:2})
h({x:3})
React Createfactory, Createclass, and createelement are used in what scenarios, why is it so defined?