Skip to main content
Version: 8.10.1

Custom Components

Draft

This documentation is still a work in progress. If you have any questions, ask to the discussions page on Github.

Use the components prop to replace some of the internal components used by DayPicker with a custom implementation.

For example, if you need to customize the component creating the day cell, you can replace the DayContent component with a custom implementation.

./CustomDayContent.tsx
import { type DayContentProps } from "react-day-picker";

/** Replace the 19th with an emoji */
export function CustomDayContent(props: DayContentProps) {
return (
<span style={{ position: "relative", overflow: "visible" }}>
{props.date.getDate() === 19 ? ` 🎉` : props.date.getDate()}
</span>
);
}

Then passed the custom component to the DayPicker component:

./MyApp.jsx
import { CustomDayContent } from "./CustomDayContent";

<DayPicker
components={{
DayContent: CustomDayContent // Replace the DayContent component
}}
/>;

Supported Components​

The customizable components are defined in the CustomComponents interface. Pass any of these to the components prop.

warning

The custom components are not part of the stable API yet, and may change in future versions.

DayPicker Hooks​

When creating custom components, you will find useful the DayPicker hooks.

import { useDayPicker } from "react-day-picker";

Examples​

Custom Caption​

Implement a custom Caption component with next/previous buttons. Note the use of the useNavigation hook to navigate between months.

import { format } from "date-fns";
import { CaptionProps, DayPicker, useNavigation } from "react-day-picker";

function CustomCaptionComponent(props: CaptionProps) {
const { goToMonth, nextMonth, previousMonth } = useNavigation();
return (
<h2>
{format(props.displayMonth, "MMM yyy")}
<button
disabled={!previousMonth}
onClick={() => previousMonth && goToMonth(previousMonth)}
>
Previous
</button>
<button
disabled={!nextMonth}
onClick={() => nextMonth && goToMonth(nextMonth)}
>
Next
</button>
</h2>
);
}

export function CustomCaption() {
return (
<DayPicker
components={{
Caption: CustomCaptionComponent
}}
/>
);
}

Range Selections with Shift Key​

Implement a custom Day component to select ranges while pressing the Shift key. See examples/RangeShiftKey.tsx for the full source code.