This hook is used to create a form from a document and an entity. It will create a form with the fields defined in the document's input type. It will also create a submit handler that will submit the form to the server.
This hook is mostly used internally by the higher-level useDetailPage hook, but can in some cases be useful to use directly.
Example
Parameters
GeneratedFormOptions<T, VarName, E>Metadata passed as the second argument to a GeneratedFormOptions onSubmit
handler, describing which fields the user changed relative to the loaded entity.
ReadonlySet<string>The set of top-level input field names the user actually changed relative to
the loaded entity (plus non-nullable fields which are always included).
undefined when creating a new entity (there is no baseline to diff against).
Options for the useGeneratedForm hook.
TThe document to use to generate the form.
VarNameThe name of the variable to use in the document.
E | null | undefinedThe entity to use to generate the form.
any[](schema: ZodObject<any>) => ZodTypeAnyv3.7.0Refines the auto-generated Zod schema before it is passed to the form resolver. Use this to declare the fields which must actually be filled in by the user.
The generated schema is derived from the GraphQL input type, which only expresses nullability — and nullability tells you nothing about whether a value is required:
String! means "not null", not
"not empty", and a non-nullable ID! such as CreateFacetValueInput.facetId may be
supplied by the page in transformCreateInput rather than by the user.CreateChannelInput. defaultCurrencyCode is nullable, yet ChannelService.create rejects the input unless
it is set.Note that this is read once, when the schema is first built: it is held in a ref so that an inline arrow function does not replace the resolver on every render.
Example
( entity: NonNullable<E>, ) => WithLooseCustomFields< VarName extends keyof VariablesOf<T> ? VariablesOf<T>[VarName] : VariablesOf<T> >WithLooseCustomFields< Partial<VarName extends keyof VariablesOf<T> ? VariablesOf<T>[VarName] : VariablesOf<T>> >v3.8.0The starting values to apply on top of the default values when there is no entity. They count as
unsaved changes. The form resets whenever they change, so values such as new Date() should not
be recreated on every render.
( values: VarName extends keyof VariablesOf<T> ? VariablesOf<T>[VarName] : VariablesOf<T>, meta?: GeneratedFormSubmitMeta, ) => void