I'm confused about how to handle react-dates[DateRangePicker] onDatesChange and onFocusChange because they have two values each. onDatesChange should be able to set multiple values i.e both start date and end date.
I was trying to build a custom wrapper around the daterangepicker with formik.
Check console for errors
`<div className="form-group">
<label>DatePickerWithFormik</label>
<Field component={DatePickerWithFormik} name="DatePickerWithFormik"
className="form-control" />
</div>`
`export const DatePickerWithFormik = ({ startDateId, endDateId, form: { setFieldValue, setFieldTouched }, field, ...props }) => {
const [focused, setFocused] = useState(null); // this will be removed
return(
<div>
{/* {console.log('Inside datpicer', field.name)} */}
<DateRangePicker
{...props}
startDateId="startDateId"
endDateId="endDateId"
onDatesChange={(value) =>
field.onChange(setFieldValue(field.name, value) )}
onFocusChange={focused => setFocused(focused)}
focusedInput={focused}
startDate={field.startDate}
endDate={field.endDate}
/>
{/* {console.log(field)} */}
</div>
);
};
`
- Expected result: Should be able to save both start and end dates in local state and display it on screen.
Refer working link: https://codesandbox.io/s/l72w6n8l0m