#Passing non-serializable objects (Date, etc) from server to client components

1 messages · Page 1 of 1 (latest)

vital egret
#

I haven't done it myself and I'm not sure of your exact situation, but I can help with general tips I suppose

opaque blaze
#

here's the code for reference

lost snow
vital egret
#

yeah, you can just use the string conversion methods, you don't need superjson necessarily

#

I tried making an example on codesandbox, but it doesn't run a high enough version to support the newest app-directory features of next 13

#

What you'll need to model is in the body of page.tsx and ClientComponent.tsx

#

You'll need to either mutate the dates inside each article to turn them into strings, or create a new articles with stringified dates

#

if you don't want to use superjson (you don't really need it), substitute the two methods with date.toISOString() and new Date(date) respectively