malfoy
malfoy

Reputation: 80

how do I change the date set on a dayjs date picker

So I am using dayjs with ANTD v5.16.4 with react 18.2.0. I have a form that the user fills in, they fill-in a bunch of info select a date from the date picker, and submits. This now stored on a mongodb cloud.

The date is store in "YYYY-MM-DD" format which is converted from a dayjs object. ie <selected_date>.format("YYYY-MM-DD").

Let's say a user comes back to make some changes to the info. I pull the data and save it on the state. Then that info(date) is read by the date picker in this piece of code.

<DatePicker
                              value={
                                estimatedShippingDate
                                  ? dayjs(estimatedShippingDate)
                                  : null
                              }
                              onChange={(date) =>
                                handleShippingDateChange(date, index)
                              }
                              style={{ width: "100%" }}
                              allowClear
                              disabledDate={(current) =>
                                current && current < today
                              }
                            />
                          </div>

The date picker show the date it was saved. I can clear the previously entered date, which sets it to null.

The issue now comes when I click on the date picker. As soon as I click on it to change the date. The page crashes and throws an error "TypeError: t.weekday is not a function. (In 't.weekday()', 't.weekday' is undefined)".

I tried to set it as a date string in the ISO date format but still no luck.

Upvotes: 0

Views: 657

Answers (1)

malfoy
malfoy

Reputation: 80

I followed this post: https://stackoverflow.com/questions/76650410/antd-dayjs-typeerror-clone-weekday-is-not-a-function" weirdly it works. Still need to figure out what imports are required rather than all.

Upvotes: 0

Related Questions