[**Documentation**](../../../README)

***

[Documentation](../../../README) / [@zerotal/inertia](../README) / optional

# Function: optional()

> **optional**(`callback`): [`OptionalProp`](../classes/OptionalProp)

Defined in: [inertia/src/props/PropTypes.ts:259](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/inertia/src/props/PropTypes.ts#L259)

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`](../type-aliases/PropFactory)

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

## Returns

[`OptionalProp`](../classes/OptionalProp)

An [OptionalProp](../classes/OptionalProp) wrapper for the resolver.

## Example

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