Decimal objects are not supported
Unanswered
Thai posted this in #help-forum
ThaiOP
When using prisma what is the correct way to solve passing an object with a
I have tried using Superjson and I couldn't get it to work or at least I kept getting the same error. Is there another option?
Decimal property on it?Warning: Only plain objects can be passed to Client Components from Server Components. Decimal objects are not supported.I have tried using Superjson and I couldn't get it to work or at least I kept getting the same error. Is there another option?
7 Replies
@Thai When using prisma what is the correct way to solve passing an object with a `Decimal` property on it?
Warning: Only plain objects can be passed to Client Components from Server Components. Decimal objects are not supported.
I have tried using Superjson and I couldn't get it to work or at least I kept getting the same error. Is there another option?
what is this
Decimal property? i don't know of any vanilla js thingy named Decimalif it's from a third party lib, that means it cannot be serialised automatically and you have to do the serialisation/deserialisation manually yourself
ThaiOP
Yeah this is coming from prisma
Was hoping for a good standard solution since prisma is so widely used
@Thai Yeah this is coming from prisma
it's from
decimal.js so you need to manually serialise it with e.g. [toJSON](https://mikemcl.github.io/decimal.js/#toJSON) then manually deserialise it on the client side with maybe new Decimal(json value)a general solution for unserialisable values is to use something like
superjson yes, but superjson doesn't support a third party API like this oneso you have to do
superjson's job: convert the decimal to a JSON-compatible value (with toJSON it should be a string), then convert that value back to a decimal value on the client-side