문제

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>
    );
  }
});
도움이 되었습니까?

해결책

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

다른 팁

If you find it more convenient, you're free to do that but there's little to no performance benefit from doing so. Object property accesses are generally very fast.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top