react-nice-calendar doesn't display the current year. I've struggled with the same issue and found an elegant workaround.
It is possible to hide the month with CSS in the upper navigation and then add your own month.
- Hide the built-in month:
.nice-dates-navigation_current {
display: none;
}
- Add your own month and year with proper formatting and styling
<p className="calendar__current-date">
{selectedDate.month}
</p>
<Calendar
locale={enGB}
month={selectedDate.date}
onMonthChange={handleMonthChange}
/>
- Finally manage the state of the
Calendar
import { format } from 'date-fns'
...
const [selectedDate, setSelectedDate] = useState<{
date: Date
month: string
}>({
date: new Date(),
month: format(new Date(), 'MMMM yyyy', { locale: enGB })
})
...
const handleMonthChange = (date: any) => setSelectedDate({
date,
month: format(date, 'MMMM yyyy', { locale: enGB })
})