为了让我的代码轻松合理,我想将繁重的渲染代码移到主渲染()之外的函数中。这是否会造成状态更改问题或稍后导致调试/性能问题。
React 很新,只是想确保我以后不会引起头痛。
几个例子
const Example = (props) => {
return (
<div>
<p>All the cool things</p>
</div>
);
};
对比
const Example = (props) => {
const renderCoolThings = (
<p>All the cool things</p>
)
return (
<div>
{renderCoolThings()}
</div>
);
};
两种方式似乎都可以正常工作,但要确保这是一种有效的方法