I’m using react-calendar to create a customised calendar. Is it possible to replace default week numbers with custom week numbers?
<Calendar
calendarType="US"
onChange={handleDateChange}
showWeekNumbers
onClickWeekNumber={handleWeekClick}
selectRange
value={[new Date(selectedStartDate), new Date(selectedEndDate)]}
defaultValue={[
new Date(selectedStartDate),
new Date(selectedEndDate),
]}
formatShortWeekday={(_locale, date) => weekday[date.getDay()]}
/>
I was not able to find any documentation or examples on how this can be achieved. I could add the custom week numbers separately beside the calendar but they would not be clickable and would not highlight the dates in the calendar.
2
Answers
You visit this https://github.com/wix/react-native-calendars/issues/1072
stylesheet.day.basic.weekNumbers ?
stylesheet.calendar.header.weekNumber ?
If you need to make the week numbers and associated start and end dates dynamic, you can fetch the data from an API and then use it to populate the custom week numbers and their corresponding dates. Here’s how you could modify the approach to make it dynamic:
Fetching Data from API:
Create a function that fetches the week numbers and associated dates from your API. You can use JavaScript’s fetch API or a library like axios for this purpose. Assume your API returns data in a format like:
Rendering Dynamic Custom Week Numbers:
After fetching the data, you can map over the received week data to dynamically render the custom week numbers and dates. Each custom week number can have an onClick handler to handle interactions.