【发布时间】:2021-08-27 14:15:09
【问题描述】:
这是对象,假设我要在列表中添加一些内容:[],我该怎么做?我知道我们可以使用 prevList 回调来做到这一点,但我对映射它有点困惑。
const [boardlist, setBoardlist] = useState([
{
id: 1,
boardName: "home work",
data: [
{
id: 1,
header: "Stuff to do",
list: [
{
id: 1,
taskTitle: "working from home",
},
],
},
{
id: 2,
header: "In Progress",
list: [],
},
{
id: 3,
header: "Done",
list: [],
},
],
},
]);
【问题讨论】:
-
如果浏览此数据结构是个问题,请参阅:How can I access and process nested objects, arrays or JSON?
-
专门针对处于状态的数组:Correct modification of state arrays in React.js
-
你看到了,但我仍然对我拥有的数组感到困惑,如果我能得到一点帮助,那真的很有帮助。
-
您应该包括一个明确的用例,您为使其工作所做的尝试 (minimal reproducible example) 以及哪些不工作。
标签: javascript reactjs use-state