I'm using ReactJS (by facebook) and I have the option of calling setState
or setProps
, but don't know which is more efficient performance-wise.
(Don't take my code on face value. This is just a simplification. My main concern is knowing which of setProps
or setState
is faster.)
For setProps I have:
function XHRcallback(data) {
React.renderComponent(MainApp, $("container")).setProps(data);
}
For setState I have:
var updateAll;
function XHRcallback(data) {
updateAll(data);
}
var List = React.createClass({
getInitialState: function() {
updateAll = function(data) {
this.setState(data);
}.bind(this);
},
render: function() {
//stuff
}
});
State and props are equally efficient in React; they're used for different things. Think of props
as inputs to your component, and state
as internal, private variables.
See Thinking in React for a discussion of state vs. props.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With