Next.js Discord

Discord Forum

how to pass zod object from server component to client components as props

Answered
Giant panda posted this in #help-forum
Open in Discord
Avatar
Giant pandaOP
how to pass zod object from server component to client components as props
Answered by Alfonsus Ardani
zod arent serializable; this means not only that it wouldn't work passing server to client, but storing it to a database. I think its better you change to a library that supports serializable schema like [superstruct](https://docs.superstructjs.org/)
View full answer

10 Replies

Avatar
@Giant panda how to pass zod object from server component to client components as props
Avatar
why do you want to do that? zod schemas are static so can be imported to the client components directly
Avatar
@joulev why do you want to do that? zod schemas are static so can be imported to the client components directly
Avatar
Giant pandaOP
to create some basic fields based on schema
Avatar
@Giant panda to create some basic fields based on schema
Avatar
you meant to create dynamic schema based on user input?
Avatar
Giant pandaOP
yes
want to store schema in db and fetch and give to a client component
Avatar
why do you need to store the schema in the db again?
Avatar
Giant pandaOP
to create some basic fields based on schema,
schema that can be changed by the users -> so want to, also store it in db
Avatar
@Giant panda to create some basic fields based on schema, schema that can be changed by the users -> so want to, also store it in db
Avatar
zod arent serializable; this means not only that it wouldn't work passing server to client, but storing it to a database. I think its better you change to a library that supports serializable schema like [superstruct](https://docs.superstructjs.org/)
Answer
Avatar
or you know, you can make your own schema parser, you know, keep the scope small