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

178
Views
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
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!