Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
How to handle multiple Material UI Slide Component

I am using Material UI Slide. Here Is my code. What I want to do is, individual slide will appear when I hover over a certain card. but with this code, both slide is appearing when hovering any one of the cards.

handler:

const [checked, setChecked] = useState(false);
const handleSlide = () => {
      setChecked(!checked);
  };

jsx:

<Card onMouseEnter={handleSlide} onMouseLeave={handleSlide} sx={{ maxWidth: 345 }}>
  <CardContent>
    <Typography gutterBottom variant="h5" component="div">
      Card 1
    </Typography>
    <Typography variant="body2" color="text.secondary">
      Lizards are a widespread group of squamate reptiles, with over 6,000
      species, ranging across all continents except Antarctica
    </Typography>
  </CardContent>
  <Slide direction="up" in={checked}>
    <CardActions>
      <Button size="small">Button 1</Button>
      <Button size="small">Button 2</Button>
    </CardActions>
  </Slide>
</Card>

<Card onMouseEnter={handleSlide} onMouseLeave={handleSlide} sx={{ maxWidth: 345 }}>
  <CardContent>
    <Typography gutterBottom variant="h5" component="div">
      Card 2
    </Typography>
    <Typography variant="body2" color="text.secondary">
      Lizards are a widespread group of squamate reptiles, with over 6,000
      species, ranging across all continents except Antarctica
    </Typography>
  </CardContent>
  <Slide direction="up" in={checked}>
    <CardActions>
      <Button size="small">Button 1</Button>
      <Button size="small">Button 2</Button>
    </CardActions>
  </Slide>
</Card>

What should I do to achieve what is want.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

My understanding after reading your question, in your code both cards are using the same state as a result when you hover any of them affect both. To make each card behave uniquely you have to make sure each component uses its own state, not common state. For this, my suggestion is to make a new Card component with State and Handler methods. then render it where the cards are rendered right now. like bellow.

New card component:

const CardComponent = (props) => {
    const [checked, setChecked] = useState(false);
    const handleSlide = () => {
        setChecked(!checked);
    };
    return (
        <React.Fragment>
            <Card onMouseEnter={handleSlide} onMouseLeave={handleSlide} sx={{ maxWidth: 345 }}>
                <CardContent>
                    <Typography gutterBottom variant="h5" component="div">
                        {props.title}
                    </Typography>
                    <Typography variant="body2" color="text.secondary">
                        Lizards are a widespread group of squamate reptiles, with over 6,000
                        species, ranging across all continents except Antarctica
                    </Typography>
                </CardContent>
                <Slide direction="up" in={checked}>
                    <CardActions>
                        <Button size="small">Button 1</Button>
                        <Button size="small">Button 2</Button>
                    </CardActions>
                </Slide>
            </Card>
        </React.Fragment>
    );
}

Then replace your card with this new card component and pass properties to each card as props.

<CardComponent title={'Card 1'} />
<CardComponent title={'Card 2'} />

I hope this will solve your issue.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda