CalendarProvider
An alternative approach for using a calendar. This provider gives you the properties of a calendar as render props.
The naming scheme is probably confusing, might be renamed to something else in the future.
Parameters
Name | Type | Default | Description |
---|---|---|---|
initialDate | Date | new Date() | The date to use as the base for the calendar, the month is chosen based off this date. |
children | Function | - | A function that returns a React element. |
import { CalendarProvider } from 'react-temporal-ui';
const Calendar = () => {
return (
<CalendarProvider>
{({ weeks, nextMonth, prevMonth }) => (
<>
<button onClick={prevMonth}>Prev</button>
<button onClick={nextMonth}>Next</button>
{weeks.map((week, i) => (
<div key={i}>
{week.map((day, j) => (
<p>{day.getDate()}</p>
))}
</div>
))}
</>
)}
</CalendarProvider>
);
};