javascript - 有没有办法在解构对象时访问对象本身?
问题描述
作为一个很好的例子,考虑这样的反应组件:
const MyComponent = (props) => {}
在上面的组件中,我们可以像这样访问 props 的孩子:
const MyComponent = ({count, value, ...rest}) => {}
并且使用 ...rest,我们也可以有未列出的孩子。
我的问题是,有没有办法在使用和不使用道具的情况下访问所有孩子?像这样的东西:
const MyComponent = ({count, value } = props) => { // I know this is wrong, it's just an example
return <>{props.count} {value} {props.someThingNotListed} </>
// getting able to access to destructed child direclty or by using props if we want
}
解决方案
推荐阅读
- algorithm - 填充树的 Dp 方法和递归
- ios - NWConnection, 100% CPU 使用率和发送 512 UDP 数据包后崩溃
- docker - 在 Docker 容器内进行 VS Code 开发时启动 GUI 应用程序 (Firefox)
- c# - 为什么在添加运动控制器时角色会摔倒?
- audio - 有没有办法使用 Amplitude 类实时分析来自外部源的音频数据?
- r - Tidy multiple anovas
- php - 如何显示味精 php joomla
- kotlin - IntelliJ IDEA:为什么 readLine() 需要两个用户输入而不是一个使用 Kotlin 的输入?
- html - 我无法将我的 css 文件链接到我的 html 文件,并且在之前的任何帖子中都找不到我的问题的解决方案
- android - 在进行 UI 测试 Android 时打开/关闭位置