useWeekNumbers
@volvo-cars/react-calendar v0.6.0
Returns one ISO 8601 week number for each week row in the month a calendar currently shows. Use it to build a custom week number column. The WeekNumbers component uses it.
The hook reads the calendar state from context. Call it inside a Calendar or RangeCalendar. Outside of one, it throws an error.
Render a week number for each row next to the calendar grid:
import { useWeekNumbers } from '@volvo-cars/react-calendar';
function WeekColumn() { const weekNumbers = useWeekNumbers({ isRange: false, offset: 0 });
return ( <ol className="micro text-secondary"> {weekNumbers.map((number) => ( <li key={number}>{number}</li> ))} </ol> );}For a range calendar, set isRange to true. To read the second month in a two-month view, set offset to 1.
useWeekNumbers(options) accepts:
isRange:trueto read the state of aRangeCalendar,falseto read the state of aCalendaroffset: number of months to move forward from the first visible month. Use0for the first visible month
Returns number[]: the week number for each week row of the month, in order. Weeks follow the locale’s first day of the week, and the number comes from the Thursday of each row.