State

Code

const [data, state, request] = useApi(config, options)

First State (before calling API)

The first state has only one property loading before calling API.

Name

Type

Default

Description

loading

boolean

false

To indicate whether calling api or not.

fromCache

boolean

false

To tell whether the data come from SSR API cache.

Full State

The is the full state data structure after the api has responded.

Name

Type

Default

Description

loading

boolean

false

To indicate whether calling api or not.

fromCache

boolean

false

To tell whether the data come from SSR API cache.

data

any

undefined

The processed data provided from options.handleData.

response

AxiosResponse

undefined

The Axios' response.

error

AxiosError

undefined

The Axios' error.

dependencies

Object

undefined

The additional needed data using in handleData. NOTE: "dependencies" is supposed to immutable due to React's rendering policy.

prevData

any

undefined

The previous data of the previous state.

prevState

ReactUseApi.State

undefined

The previous state.

[custom data]

any

You can add your own custom state data into the state by setting up in options.handleData. For example, state.foo = 'bar'. The data always be preserved whether re-rendering.

Last updated