1

I am trying to send data as props to the child component after changing the date but if I try to console the date inside Child component I am getting undefined.

I am setting the value inside date on an onChange event.

This is the Parent Component :-

import { useState } from "react"
import Child from "./Child"

const Parent = () => {
    const [date, setDate] = useState();
    
    const onChange = (e) => {
        setDate(e.target.value)
        console.log(date)
    }

    return(
        <div>
            <input type="date" onChange={onChange}></input>
            <Child date={date}/>
        </div>
    )
}

export default Parent


And this is the Child Component

const Child = (props) => {
    console.log(props.date)
    return(
        <div>
          <h2>Child</h2>
        </div>
    )
}

export default Child
Drew Reese
  • 165,259
  • 14
  • 153
  • 181

0 Answers0