我有一个问题,状态的重新呈现会导致ui问题,有人建议只更新我的reducer中的特定值,以减少页面上的重新呈现量.
这是我所在州的一个例子
{
name: "some name",
subtitle: "some subtitle",
contents: [
{title: "some title", text: "some text"},
{title: "some other title", text: "some other text"}
]
}
我现在正在像这样更新它
case 'SOME_ACTION':
return { ...state, contents: action.payload }
其中action.payload
是包含新值的整个array.但现在我实际上只需要更新内容数组中第二项的文本,这样的东西不起作用
case 'SOME_ACTION':
return { ...state, contents[1].text: action.payload }
其中action.payload
现在是我需要更新的文本.