![](/img/trans.png)
[英]How can I update the React Native state if I have an array inside an object and the object is inside in a big array?
[英]How can I update a state inside an array of object with Redux?
我的應用程序有 2 個選項卡,我需要根據選項卡中的點擊修改內容,我有以下狀態:
const example = {
tabs: [
{
id: 111,
title: 'Python',
icon: 'Python@2x.svg',
content: 'Hello World'
},
{
id: 333,
title: 'EQL',
icon: 'EQL@2x.svg',
content: 'Hello World 2'
}
]
}
我需要更改選項卡內的“內容”。 我試過這個:
return {
...state,
tabs: {
...state.tabs,
content: 'Uhuuuul'
}
}
但這沒有用! 有人可以解釋為什么嗎?
使用map
:
return {
...state,
tabs: state.tabs.map(tab => ({...tab, content: "Uhuuuul"}))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.