Skip to content

Release v21.16.0

Choose a tag to compare

@github-actions github-actions released this 15 Aug 06:48
b086210

Added

  • CommandForm accepts populateFromQuery/populateFromObservableQuery (plus shared populateFromQueryArgs) to seed its initial values from a single-instance query's result, matched onto the command's properties by name.
  • usePopulateFromQuery/usePopulateFromObservableQuery - the underlying hooks, usable directly outside CommandForm.
  • Two new field props (available on every field type, since they flow through asCommandFormField): noInitialValue skips a field entirely; initialValue overrides how a field's value is derived from the population source - either a property accessor matched by name, or a function composing a value from the whole source.
  • A query that turns out to return multiple instances throws QueryReturnsMultipleInstances - a form's initial values only ever come from one instance.
  • The resolved data becomes the form's baseline through the command's own change tracking, not just a value overlay - hasChanges reads false right after population, and validation only reruns when the resolved data itself changes.
  • New "Populating a Form from a Query" documentation section, cross-linked from the existing manual fetch-and-seed pattern.

(#2549)

Notes for reviewers

The issue asks for a single mechanism supporting both regular and observable queries. React's Rules of Hooks make one unified prop that auto-detects regular-vs-observable at runtime genuinely hard, without resorting to a synthetic fallback query class that carries its own risk. This PR exposes two explicit props instead (populateFromQuery / populateFromObservableQuery) - the caller picks whichever matches their query's actual type at the type level, with no runtime branching required.