Nate David-Peter
Nate David-Peter

Reputation: 21

Modal onClick glitch

This is doing my head in, why is my onClick not working in this line

<ProjectCard onClick={openModal} {...projectObjOne}  />

I feel like it may be a simple syntax error here is the function ive written

const [showModal, setShowModal] = useState(false);

const openModal = () => {
setShowModal(!showModal);

console.log('clicked')
};

Thanks

Upvotes: 0

Views: 95

Answers (1)

theWellHopeErr
theWellHopeErr

Reputation: 1872

Assuming ProjectCard is a user-defined component.

onClick attribute is not predefined in user-defined components. You can either send this as a prop and handle it in the component or use HTML tag as a parent.

<div onClick={openModal} >
  <ProjectCard/>
</div>

Upvotes: 2

Related Questions