JSX:传递道具的冗余程度较低

问题描述 投票:1回答:1

这可能是一个愚蠢的问题。我有一个正在使用的JSX元素,如下所示:

<Editor 
  editor={editor}
/>

有一种方法,类似于ES6 +如何让您能够使用对象的键(如果这些键与值相同),使用简写形式将具有相同名称的变量作为道具来使用?

reactjs jsx
1个回答
0
投票

是的,您可以这样简单地使用spread

<Editor {...{editor}} />

参考https://reactjs.org/docs/jsx-in-depth.html

© www.soinside.com 2019 - 2024. All rights reserved.