Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda