[英]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.