import React, { useState } from "react";
import "./styles.css";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
export default function MyComponent() {
const [date, setDate] = useState(new Date());
const handleChange = (date) => setDate(date);
return <DatePicker selected={date} onChange={handleChange} />;
}
Here is my working codesandbox:- https://codesandbox.io/s/basic-datepicker-forked-4zyzv4?file=/src/MyComponent.js
Here is a small bug in my code. For example, Assume i have two datepickers one after another, when i try to select date from one datepicker, other datepicker also taking the same value.?
What exactly wrong with my code? For handleChange event, Do i need to take unique id for each? Can you please suggest what's wrong with my code.