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

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

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 Relatório

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