html - Reactjs 中的 Props 简写

标签 html reactjs svelte shorthand

在 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/

相关文章:

html - 在 flexbox 布局中调整图像大小

node.js - 将 jwt 暴露给客户端可能会导致安全问题

css - 计算机和移动设备的网络用户界面相同吗?

php - 德鲁帕尔 7 : Localhost/user link defaults to website/user

html - CSS Padding 在固定高度 div 悬停时溢出

javascript - 无法更改所选选项的背景颜色 | react 选择

javascript - 按多个条件过滤数组

svelte - 解析错误: Colon is expected (svelte with scss style) svelte unit testing

routing - 在 Sapper 中作为模态路由

javascript - 如何在 Svelte 中使用 Web 组件?