Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React JSX: Cache Props?

Tags:

reactjs

When accessing the same props value multiple times in React/JSX, is it advisable 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>
    );
  }
});
like image 967
cantera Avatar asked Dec 04 '25 16:12

cantera


1 Answers

The props are just properties on a JavaScript object – not getter functions, so there shouldn't be any noticeable difference in performance.

like image 91
Michael LaCroix Avatar answered Dec 07 '25 15:12

Michael LaCroix