1
- import React , { createContext , useState , useContext } from 'react'
1
+ import React , { createContext , useState , use } from 'react'
2
2
import dayjs from 'dayjs'
3
3
import duration from 'dayjs/plugin/duration'
4
4
import isBetween from 'dayjs/plugin/isBetween'
@@ -74,7 +74,7 @@ export function DatePicker({
74
74
setBaseMonth,
75
75
}
76
76
77
- return < Context . Provider value = { context } > { children } </ Context . Provider >
77
+ return < Context value = { context } > { children } </ Context >
78
78
}
79
79
80
80
/****************************************
@@ -87,7 +87,7 @@ type DatePickerCalendarProps = {
87
87
}
88
88
89
89
export function DatePickerCalendar ( { offset = 0 } : DatePickerCalendarProps ) {
90
- const { baseMonthFirst, selectDate, selectedDates } = useContext ( Context )
90
+ const { baseMonthFirst, selectDate, selectedDates } = use ( Context )
91
91
// The first day of the base month
92
92
const theFirst = offset === 0 ? baseMonthFirst : baseMonthFirst . add ( offset , 'month' )
93
93
@@ -160,7 +160,7 @@ type DatePickerChangeMonthProps = {
160
160
} & React . HTMLAttributes < HTMLButtonElement >
161
161
162
162
export function DatePickerChangeMonth ( { children, to, ...props } : DatePickerChangeMonthProps ) {
163
- const { setBaseMonth } = useContext ( Context )
163
+ const { setBaseMonth } = use ( Context )
164
164
return (
165
165
< button { ...props } data-datepicker-change-month = "" onClick = { ( ) => setBaseMonth ( to ) } >
166
166
{ children }
@@ -178,6 +178,6 @@ type DatePickerLabelProps = {
178
178
}
179
179
180
180
export function DatePickerLabel ( { format = 'MMMM' , offset = 0 } : DatePickerLabelProps ) {
181
- const { baseMonthFirst } = useContext ( Context )
181
+ const { baseMonthFirst } = use ( Context )
182
182
return < > { baseMonthFirst . add ( offset , 'month' ) . format ( format ) } </ >
183
183
}
0 commit comments