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
Giant pandaOP
how to pass zod object from server component to client components as props
Answered by Lao Gan Ma
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

@Giant panda how to pass zod object from server component to client components as props
why do you want to do that? zod schemas are static so can be imported to the client components directly
@joulev why do you want to do that? zod schemas are static so can be imported to the client components directly
Giant pandaOP
to create some basic fields based on schema
@Giant panda to create some basic fields based on schema
you meant to create dynamic schema based on user input?
Giant pandaOP
yes
want to store schema in db and fetch and give to a client component
why do you need to store the schema in the db again?
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
@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
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
or you know, you can make your own schema parser, you know, keep the scope small