I am using redux and I want to destructure teamMembers - Array from an 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);
 
                        
If possible, you should not do
Your code here is interested in
descriptionandheading, but youruseSelectorselects the wholeteamData. Now, if there is a third property onteamData, let's saywinStreakand thatwinStreakchanges, your component will rerender. Because that change towinData.teamStreakcausedwinDatato change. And youruseSelectoris watchingwinDatafor changes.If you instead do
your component will only rerender, when
descriptionorheadingchange. Because youruseSelectornow watches those two properties for changes. It does not care ifteamDatachanges, it only cares if teamData.descriptionorteamData.heading` change.So, in your case you should do
and not use any destructuring here. If you have to destructure the result of a
useSelectorcall, that likely means that youruseSelectorcall is also observing data you are not interested in in the first place.