React JSX: Cache Props?

When accessing the same value propsat the same time in React / JSX, is it recommended to cache the object in a local variable?

var ItemComponent = React.createClass({

  render: function() {

    var cached = this.props.item;

    return (
      <div className={cached.class}>
        <h1>{cached.heading}</h1>
        <p>{cached.text}</p>
      </div>
    );
  }
});
+3
source share
2 answers

props are simply properties of a JavaScript object, not a getter function, so there should be no noticeable difference in performance.

+5
source

If you find this more convenient, you can do it, but there is little benefit from performance. Access to object properties is usually very fast.

+3
source

All Articles