Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!