Skip to content

Commit

Permalink
docs: fix custom-multiple example
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Jan 25, 2023
1 parent 3e4eefc commit 6dcaa4b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions website/examples/custom-multiple.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import React, { useState } from 'react';

import { isSameDay } from 'date-fns';
import { DayClickEventHandler, DayPicker } from 'react-day-picker';

export default function App() {
const [selectedDays, setSelectedDays] = useState<Date[]>([]);

const handleDayClick: DayClickEventHandler = (day, modifiers) => {
setSelectedDays((currentValue) => {
const days = [...currentValue];
if (modifiers.selected) {
days.splice(currentValue.indexOf(day), 1);
} else {
days.push(day);
}
return days;
});
const newSelectedDays = [...selectedDays];
if (modifiers.selected) {
const index = selectedDays.findIndex((selectedDay) =>
isSameDay(day, selectedDay)
);
newSelectedDays.splice(index, 1);
} else {
newSelectedDays.push(day);
}
setSelectedDays(newSelectedDays);
};

const handleResetClick = () => setSelectedDays([]);
Expand Down

0 comments on commit 6dcaa4b

Please sign in to comment.