# State properties

These are returned in an object by `useAsync()` or provided by `<Async>` as render props to the `children` function:

* [`data`](/api/state.md#data) Last resolved promise value, maintained when new error arrives.
* [`error`](/api/state.md#error) Rejected promise reason, cleared when new data arrives.
* [`value`](/api/state.md#value) The value of `data` or `error`, whichever was last updated.
* [`initialValue`](/api/state.md#initialvalue) The data or error that was provided through the `initialValue` prop.
* [`startedAt`](/api/state.md#startedat) When the current/last promise was started.
* [`finishedAt`](/api/state.md#finishedat) When the last promise was fulfilled or rejected.
* [`status`](/api/state.md#status) One of: `initial`, `pending`, `fulfilled`, `rejected`.
* [`isInitial`](/api/state.md#isinitial) true when no promise has ever started, or one started but was cancelled.
* [`isPending`](/api/state.md#ispending) true when a promise is currently awaiting settlement. Alias: `isLoading`
* [`isFulfilled`](/api/state.md#isfulfilled) true when the last promise was fulfilled. Alias: `isResolved`
* [`isRejected`](/api/state.md#isrejected) true when the last promise was rejected.
* [`isSettled`](/api/state.md#issettled) true when the last promise was fulfilled or rejected (not initial or pending).
* [`counter`](/api/state.md#counter) The number of times a promise was started.
* [`promise`](/api/state.md#promise) A reference to the internal wrapper promise, which can be chained on.
* [`run`](/api/state.md#run) Invokes the `deferFn`.
* [`reload`](/api/state.md#reload) Re-runs the promise when invoked, using any previous arguments.
* [`cancel`](/api/state.md#cancel) Cancel any pending promise.
* [`setData`](/api/state.md#setdata) Sets `data` to the passed value, unsets `error` and cancels any pending promise.
* [`setError`](/api/state.md#seterror) Sets `error` to the passed value and cancels any pending promise.

## `data`

> `any`

Last resolved promise value, maintained when new error arrives.

## `error`

> `Error`

Rejected promise reason, cleared when new data arrives.

## `value`

> `any | Error`

The data or error that was last provided (either through `initialValue` or by settling a promise).

## `initialValue`

> `any | Error`

The data or error that was originally provided through the `initialValue` prop.

## `startedAt`

> `Date`

Tracks when the current/last promise was started.

## `finishedAt`

> `Date`

Tracks when the last promise was resolved or rejected.

## `status`

> `string`

One of: `initial`, `pending`, `fulfilled`, `rejected`. These are available for import as `statusTypes`.

## `isInitial`

> `boolean`

`true` while no promise has started yet, or one was started but cancelled.

## `isPending`

> `boolean`

`true` while a promise is pending (loading), `false` otherwise.

Alias: `isLoading`

## `isFulfilled`

> `boolean`

`true` when the last promise was fulfilled (resolved to a value).

Alias: `isResolved`

## `isRejected`

> `boolean`

`true` when the last promise was rejected.

## `isSettled`

> `boolean`

`true` when the last promise was either fulfilled or rejected (i.e. not initial or pending)

## `counter`

> `number`

The number of times a promise was started.

## `promise`

> `Promise`

A reference to the internal wrapper promise created when starting a new promise (either automatically or by invoking `run` / `reload`). It fulfills or rejects along with the provided `promise` / `promiseFn` / `deferFn`. Useful as a chainable alternative to the `onResolve` / `onReject` callbacks.

Warning! If you chain on `promise`, you MUST provide a rejection handler (e.g. `.catch(...)`). Otherwise React will throw an exception and crash if the promise rejects.

## `run`

> `function(...args: any[]): void`

Runs the `deferFn`, passing any arguments provided as an array.

When used with `useFetch`, `run` has several overloaded signatures:

> `function(override: OverrideParams | (params: OverrideParams) => OverrideParams): void`
>
> `function(event: SyntheticEvent | Event): void`
>
> `function(): void`

Where `type OverrideParams = { resource?: RequestInfo } & Partial<RequestInit>`.

This way you can run the `fetch` request with custom `resource` and `init`. If `override` is an object it will be spread over the default `resource` and `init` for `fetch`. If it's a function it will be invoked with the params defined with `useFetch`, and should return an `override` object. This way you can either extend or override the value of `resource` and `init`, for example to change the URL or set custom request headers.

## `reload`

> `function(): void`

Re-runs the promise when invoked, using the previous arguments.

## `cancel`

> `function(): void`

Cancels the currently pending promise by ignoring its result and calls `abort()` on the AbortController.

## `setData`

> `function(data: any, callback?: () => void): any`

Function that sets `data` to the passed value, unsets `error` and cancels any pending promise. Takes an optional callback which is invoked after the state update is completed. Returns the data to enable chaining.

## `setError`

> `function(error: Error, callback?: () => void): Error`

Function that sets `error` to the passed value and cancels any pending promise. Takes an optional callback which is invoked after the state update is completed. Returns the error to enable chaining.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.react-async.com/api/state.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
