【发布时间】:2023-02-16 22:29:17
【问题描述】:
我正在使用 map 显示来自一组对象的卡片,我想只显示 onMouse 输入一些图标,但只显示在鼠标悬停的卡片上。现在,图标显示在所有卡片上
const onMousseEnter = (index) => {
if (index === interestsList[index].id) {
setVisibility(true);
}
};
{interestsList
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
.map((el, index) => (
<InterestCard
key={index}
onMouseEnter={() => onMousseEnter(index)}
onMouseLeave={() => onMouseLeave(index)}>
<CategoryLeftCol onClick={openCatPage(index)}>
<SurfingRoundedIcon sx={{ fontSize: 22 }} />
<Typography variant="h6" fontWeight="bold">
{el.name}
</Typography>
</CategoryLeftCol>
{visible && (
<CategoryRightCol>
<IconButton onClick={() => setOpen(true)}>
<Edit sx={{ fontSize: 14 }} />
</IconButton>
<IconButton onClick={() => setOpenAlert(true)}>
<Delete sx={{ fontSize: 14 }} />
</IconButton>
</CategoryRightCol>
)}
我可以获得鼠标悬停的卡的索引,但问题仍然存在......
【问题讨论】:
标签: javascript reactjs indexing iteration