I'm using a functional component with hooks to create a Datepicker component for my react app but I keep getting the below warning from react.
Warning: State updates from the useState() and useReducer() Hooks don't support the second callback argument. To execute a side effect after rendering, declare it in the component body with useEffect().
import React, { useState } from 'react';
import { DateRangePicker } from 'react-dates';
import 'react-dates/initialize';
import 'react-dates/lib/css/_datepicker.css';
function Datepicker() {
const [dateRange, setdateRange] = useState({
startDate: null,
endDate: null
});
const [focus, setFocus] = useState(null);
const { startDate, endDate } = dateRange;
const handleOnDateChange = (startDate, endDate) =>
setdateRange(startDate, endDate);
return (
<DateRangePicker
startDatePlaceholderText="Start"
startDate={startDate}
onDatesChange={handleOnDateChange}
endDatePlaceholderText="End"
endDate={endDate}
numberOfMonths={1}
displayFormat="MMM D"
showClearDates={true}
focusedInput={focus}
onFocusChange={focus => setFocus(focus)}
startDateId="startDateMookh"
endDateId="endDateMookh"
minimumNights={0}
/>
);
}
export default Datepicker;
I'm using a functional component with hooks to create a Datepicker component for my react app but I keep getting the below warning from react.
Warning: State updates from the useState() and useReducer() Hooks don't support the second callback argument. To execute a side effect after rendering, declare it in the component body with useEffect().