I get the data in the form of an array, and I use the .map() method to manage one state. I want to create an array that changes values individually, but it keeps moving as one. Help me.
function Follow() {
const [isFollow, setIsFollow] = useState([]);
const handleChangeButton = idx => {
const newIsFollow = [...isFollow];
newIsFollow[idx] = !newIsFollow[idx];
setIsFollow(newIsFollow);
};
return (
<FollowWrapper>
<Title>
<h5>follw</h5>
</Title>
<ul ref={ref}>
{users.map((info, idx) => {
return (
<li key={idx}>
<UserContainer>
<UserInfo onClick={() => moveDetailPage(info.product_seq)}>
<UserImage
/>
<TextWrapper>
<p>
<strong>{info.homepage_name}</strong>
<br />
{info.wholesale_client_id}
</p>
</TextWrapper>
</UserInfo>
<ButtonWrapper>
<FollowButton
isFollow={isFollow[users.length - 1]}
value={users.length - 1}
onClick={() => {
handleChangeButton(users.length - 1);
}}
>
follw
</FollowButton>
</ButtonWrapper>
</UserContainer>
</li>
);
})}
</ul>
<NavHeightBox />
</FollowWrapper>
);
}
How can I get the data and manage the state values individually? I tried to designate the state value individually, but it doesn't seem like a good way because I don't know how many data will come in.