Solid · API

createStream

Creates a stream from a Zod schema and an optional initial value. The current value starts as the initial value and is overwritten field by field as the reply is parsed, so a complete value is available to render before the first chunk arrives. Throws if initial does not validate against the schema.

Schema
z.object({
  show: z.string(),
  night: z.string(),
  seats: z.array(z.string()),
  price_cents: z.number(),
  why: z.string(),
})
Initial value
{
  show: '',
  night: '',
  seats: [],
  price_cents: 0,
  why: 'Still looking.',
}
Stream, chunk by chunk
Reply so far
{"show":"The Tempest",
Current value
{
  show: 'The Tempest',
  night: '',
  seats: [],
  price_cents: 0,
  why: 'Still looking.',
}
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.