DateTime in lucid give JSDate on react with inertia #4756
-
Hi guys, I created a model for my Orders like this : export default class Order extends BaseModel {
@column({ isPrimary: true })
declare id: UUID
@column()
declare status: IOrderStatus
@column.dateTime()
declare expiredAt?: DateTime
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
} I'm passing the order in my react page using Inertia and I try to write a comprehensible date with this code : <TableCell className="text-100 flex justify-between items-center flex-row">
{order.createdAt.toFormat('dd LLL yyyy')}
</TableCell> This code should work since TypeError: order.createdAt.toFormat is not a function When I write I can't set a format for my date using Luxon on react. Am I doing something wrong? Thanks for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @shankiflang! 👋🏻 It is because your date is being serialized when sent to Inertia (since your React application run on the client, not on the server). You have to create another instance on the client if you want to use Luxon there. |
Beta Was this translation helpful? Give feedback.
Hey @shankiflang! 👋🏻
It is because your date is being serialized when sent to Inertia (since your React application run on the client, not on the server).
You have to create another instance on the client if you want to use Luxon there.