如何破坏从redux中的对象的数组反应? 我正在使用Redux,我想破坏团队成员 - 来自对象名称的数组 - 我从Redux获得的TeamData。这就是我在下面所做的。我只想确认这是否是

问题描述 投票:0回答:1
Object name - teamData

which I am getting from REDUX. This is what I have done below. I just want to confirm whether is this the right way to do. const teamData = useSelector((state) => state.team.teamData); const { description, heading } = teamData; const teamMembers = useSelector((state) => state.team.teamData.teamMembers);

如果可能的话,您应该
redux react-redux destructuring dispatch
1个回答
0
投票
您这里的代码对

descriptionheading

感兴趣,但是您的
useSelector
选择了整个。 现在,如果在

teamData

上有第三个属性,则可以说
teamData
并且
winStreak
更改,您的组件将恢复。因为这种变化导致
winStreak
改变。而您的
winData.teamStreak
正在观看
winData
如果你做
useSelector
当您的组件时,您的组件将在
winData
const description = useSelector((state) => state.team.teamData.description);
const heading = useSelector((state) => state.team.teamData.heading );
更改时。因为您的
description
现在观看这两个属性以进行更改。它不在乎

heading

是否更改,仅在乎teamData.description

useSelector
teamData.heading`change.

,在您的情况下,您应该做 teamData

在这里不使用任何破坏性。
如果您必须破坏调用的结果,那可能意味着您的
or
呼叫也首先观察到您不感兴趣的数据。
	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.