Uncaught RangeError: date value is not finite in DateTimeFormat.format()

Playing with Flowbite React and their Datepicker component, I had data coming from the backend in this or similar form:

aka

React is a bit of a cringy special child. Angular, no problemo. Vue, no problemo.
Anyhow.

I have to set defaultValues in a React-hook-form form, because React is special with controlled and uncontrolled components.
aka

So, I’m using dayjs for my date/time stuff, and this line essentially means, parse the Date before assigning it to a form value (or create a new Date(), because React and controlled/uncontrolled forms is not a happy story).

TL;DR: Parse the date value coming from the backend into a Date object. e.g.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.