Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Show/hide element at specific index with react js

I am displaying cards from an array of objects with map, and I would like to show only onMouse enter some icons, but only on the card where mouse is hover. Right now, icons show on all card

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>
          )}

I can get the index of the card where mouse is hover but problem persist…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

className="interestCard" // for <InterestCard/>
...
className="interestCard_icons" // for <CategoryRightCol/> i guess

css:

.interestCard_icons {
    opacity: 0;
    pointer-events: none; 
    transition: opacity 0.3s;
}
.interestCard:hover .interestCard_icons {
    opacity: 1;
    pointer-events: auto;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading