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

175
Visualizações
How to show the data in a modal after an onClick event triggers in ReactJS?

I am trying to show some data in my modal component. However, when I pass the data as a prop to my modal I can see that I get the data on my useState hook, but I can not see while am using that in the Modal component.

Please see the code I tried.

const handleWatchOpen = (movieData) => {
    setWatchVideo(true)
    const videoItem = [...videoData, movieData ]
    setVideoData(videoItem)
}
const handleWatchClose =() => {
    setWatchVideo(false)
    setVideoData("")
}

<Button className = {classes.cardButton} size = "small" onClick = { () => handleWatchOpen(movie)}>Watch</Button>
<VideoModal watchVideo = {watchVideo} handleWatchClose = {handleWatchClose}  setVideoData ={setVideoData}/>

VideoModal.jsx

const VideoModal = ({
  watchVideo,
  handleWatchClose,
  setVideoData: { title },
}) => {
  const classes = useStyles();
  console.log(title);
  return (
    <>
      <Modal
        open={watchVideo}
        onClose={handleWatchClose}
        aria-labelledby="simple-modal-title"
        aria-describedby="simple-modal-description"
      >
        <div className="modal">
          <img src="" alt="img" />
          <h1>h1 {title}</h1>
          <Button
            className={classes.cardButton}
            size="small"
            onClick={handleWatchClose}
          >
            Close
          </Button>
        </div>
      </Modal>
    </>
  );
};

export default VideoModal;

Please see the console result. It says undefined and triggers more than once when I click the watch button. I do not know why. Any help or suggestions on this, please?

console image result

about 4 years ago · Juan Pablo Isaza
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