Home > Blockchain >  Why I cannot change the value of my variable?
Why I cannot change the value of my variable?

Time:05-16

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 !

CodePudding user response:

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

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