I am working on one reactjs
project. where the user needs to pick two different dates starting date and end date. When a user picks first date i need to update the state to check whether the starting date should be less than closing date ,But the problem i am facing is setState not updating state immediately. I am facing this problem during update the store timings .How can i fix this problem.
const [storeTimings, setStoreTimings] = useState({
startTime: "",
endTime: "",
startTime2: "",
endTime2: "",
});
const isValidTime = (key, value) => {
setStoreTimings({ ...storeTimings, [key]: value });
console.log({ key, value });
};
<DatePicker
onChange={(date) => {
isValidTime("startTime", date);
}}
/>