message to return to client if parsing and validating D
fails
error code of error if parsing fails
error message if parsing fails
The function throws if a data-promise is passed in and the promise rejects.
The returned parser can then be used like this:
const transform = makeParser(z.object({
createdAt: z.date()
}))
const { data } = useFetch('/example/1', { transform })
console.log(data.createdAt)
// -> output: `Date Tue Sep 06 2022 14:20:45 GMT+0200 (Central European Summer Time)`
console.log(typeof data.createdAt)
// -> output: `object` (this is a parsed date, not a date string!)
Generated using TypeDoc
Make a data transformer based on a schema. All data passed into it will be turned into data of that schema (or the transformer will throw during parsing) This method will throw an exception (like 422 Unprocessible Entity) if data validation fails. The error code and message can be customized.