在 React/JSX 中多次访问相同的 props
值时,是否建议将对象缓存在局部变量中?
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 函数,因此性能上不应该有任何明显的差异。
关于reactjs - react JSX : Cache Props?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21712193/