'Why I cannot change the value of my variable?

I have 3 components :

The first one is this one :

const App = () =>{
const [date, setDate] = useState(new Date())
return (
<MyComponent date={date} setDate={(mydate) => {setDate(mydate)}} />
)
}
export default App;

The second is that one :

const MyComponent = (props) =>{
    return (
    <MyComponent2 date={props.date} setDate={(mydate) => {props.setDate(mydate)}} />
    )
    }
    export default MyComponent;

And the last one is this one :

const MyComponent2 = (props) =>{
    props.setDate(new Date("February 5, 2001 18:15:00"))
    console.log(props.date)


    return (
    <p>Hello</p>
    )
    }
    export default MyComponent2;

But I got the following error : TypeError: props.setdate is not a function

Could you help me please ?

Thank you very much !



Solution 1:[1]

You are not receive the props, change your declaration for this :

const MyComponent = (props) => ....
const myComponent2 = (props) => ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SFournier