在 Svelte 中,当属性及其值具有相同名称时,我们可以使用简写。例如:
<img src={src} alt="">
等同于:
<img {src} alt="">
我的问题是是否有可能在 React.js 中做同样的事情?例如:
<button {type}>Click me!</button>
最佳答案
不,你不能这么做。但是您可以使用扩展运算符
来传递列表 Prop 。
const props = {src, type};
<button {...props}>Click me!</button>
关于html - Reactjs 中的 Props 简写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68832028/