[英]How to use an object in JSX
THIS QUESTION MIGHT NOT HAVE A CERTAIN ANSWER...
这个问题可能没有确定的答案......
Which approach is better to use for using an object in JSX.哪种方法更适合在 JSX 中使用对象。
1- declare an object and use that in all usages: 1-声明一个对象并在所有用法中使用它:
const object = GlobalState.getInstance().getObject()
<Component1 prop1={object}></Component1>
<Component2 prop2={object}></Component2>
<Component3 prop3={object}></Component3>
2- pass complete reference to object we want each time we use that 2- 每次使用时传递对我们想要的对象的完整引用
<Component1 prop1={GlobalState.getInstance().getObject()}></Component1>
<Component2 prop2={GlobalState.getInstance().getObject()}></Component2>
<Component3 prop3={GlobalState.getInstance().getObject()}></Component3>
which one is considered to be convention?哪一个被认为是约定俗成的? do they have any performance difference?
它们有什么性能差异吗?
It's generally considered to be a good practice to:通常认为以下做法是一种很好的做法:
This way, number one wins .这样,第一名获胜。 It's also better for performance.
这对性能也更好。 Flawless victory!
无懈可击的胜利!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.