Skip to content
Advertisement

Pass triggering button’s name as props to child modal in React

I am a beginner in React so please be patient with me ))

I have a parent component with two different buttons that trigger a child component which is a Modal that must show different data inside it depending on which button has triggered the Modal. Both components are functional components. The child Modal is supposed to receive the triggering button’s value via props from the parent. That name is a single letter that I use to construct an object’s name that gets the modal’s data from two constants defined within the Modal.

When I try to console.log the button’s name received via the props, I get an “undefined” error in the console. Consequently, I cannot construct the Modal’s contents due to that.

I prefer to define my components as functions rather that extending a class.

Is there something I am doing wrong in my code?

Parent component (Experience.jsx):

JavaScript

Child component (ExperienceModal.jsx):

JavaScript

Advertisement

Answer

setModalShow(value = true, bname = event.value) should be setModalShow({value: true, name: event.value})

props are undefined because setModalShow should recive new state value, but expression (value = true) evaluates to undefined

Advertisement