Skip to main content
zerotal

Documentation


Documentation / @zerotal/inertia / optional

Function: optional()

optional(callback): OptionalProp

Defined in: inertia/src/props/PropTypes.ts:259

Never include this prop on a full visit; the callback runs (and the value is sent) only when a partial reload names the key in its only set. Use for expensive data a page fetches on demand.

Parameters

callback

PropFactory

Factory producing the prop value (may be async); evaluated only when included.

Returns

OptionalProp

An OptionalProp wrapper for the resolver.

Example

return inertia('Users/Index', {
  users,
  // Only fetched when the client does `router.reload({ only: ['stats'] })`.
  stats: optional(() => computeExpensiveStats()),
});