简体   繁体   中英

React JSX: Cache Props?

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>
    );
  }
});

props只是JavaScript对象的属性 - 而不是getter函数,因此性能不应该有任何显着差异。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM