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

136
Views
How to render multiple modals in react?

I need to render multiple modals but the number of modals are not fixed and depend on property audios of the object coming in. I'm currently using the mui modal

This is the variables used:

  const [open, setOpen] = useState(false);
  const handleOpen = () => setOpen(true);
  const handleClose = () => setOpen(false);

And this is how I attempt to render the modals. Currently, the modal that opens after clicking 'view' only shows the last value in audios no matter which 'View' button I click on

  {audios.map((a) => (
          <Grid item container justifyContent="flex-end">
            <Button
              onClick={handleOpen}
              sx={{
                color: 'blue',
                marginTop: '0.6rem',
              }}
            >
              View
            </Button>
            <Modal
              open={open}
              onClose={handleClose}
            >       
              <Box
                sx={{
                  position: 'absolute' as 'absolute',
                  top: '50%',
                  left: '50%',
                  p: 4,
                }}
              >
            <Typography color='white'>{a.name}</Typography>
              </Box>
            </Modal>
          </Grid>
        ))}

Is there way to have separate state for open and close for each modal?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think u should put the 'open' state in the Modal component , by this way every Modal have their own state .

about 4 years ago · Juan Pablo Isaza Report

0

       const MyModalandButton=()=>{
      const [open, setOpen] = useState(false);
      const handleOpen = () => setOpen(true);
      const handleClose = () => setOpen(false);
    return <>
             <Button
              onClick={handleOpen}
              sx={{
                color: 'blue',
                marginTop: '0.6rem',
              }}
            >
              View
            </Button>
             <Modal
              open={open}
              onClose={handleClose}
            >  </>  
    }

maybe just like this

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!