Home>
When you click the button, it should print the date in the console, but in the end the date is knocked out when you go to this page and when you select the date in the picker. Nothing happens when the button is pressed. What's my mistake?
const [startDate, setStartDate]= useState(new Date());
return (
<div> <DatePicker selected={startDate} onChange={(date)=> setStartDate(date)}/> <button onClick={console.log(startDate)}>Hello</button> </div> );
-
Answer # 1
-
Answer # 2
<button onClick={()=> console.log(startDate)}>Hello</button>
Related questions
- javascript : Why do I get a jsx file instead of js after building a project with webpack using babel
- javascript : render {routes} in react
- javascript : React. Unloading ads for 10 pieces
- javascript : How to restart an existing React app?
- javascript : The simplest code on React.js does not work
- javascript : React. Send a get request to the server when pressing Enter
- javascript : Running webPack 5 in development mode does not see html page
- javascript : Problem with Route
- javascript : JS: wrap links found inside a string in an element
- javascript : How to optimize useSelector redux