gpt4 book ai didi

javascript - 使用 this.state.example 太多次,如何将其放入变量中?

转载 作者:行者123 更新时间:2023-12-01 01:21:20 25 4
gpt4 key购买 nike

我目前正在 React 中的一个 JS 文件上使用 this.state.example。我怎样才能继续将其添加到变量中,这样它就不会那么困惑?

return (
<div className="wrapper">
<header className="example">
<h1>{this.state.test.products[i].name}</h1>
</header>

我想替换 this.state.test.products

最佳答案

您可以使用 es6 语法将其提取到自己的常量中

const { example } = this.state

现在您可以在任何地方使用“example”而不是“this.state.example”

关于javascript - 使用 this.state.example 太多次,如何将其放入变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54206104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com