Passing props to hook components getting undefined

Viewed 2838

How i can pass props in two hook components?

I have a root component that uses a Modal, i need to pass to my Modal component the props title and show in the component:

<Modal title="test" />

In the modal component, i'm receiving the props as a parameter:

const Modal = (title) => {

return (
    <h6>{title}</h6>
)

But i'm receiving undefined.

I also tried with {} :

const Modal = ({title}) => {

Why?

1 Answers

You need to reference the props object in the child component:

const Modal = (props) => {

return (
    <h6>{props.title}</h6>
)

Or via destructuring:

const Modal = ({title}) => {

return (
    <h6>{title}</h6>
)
Related