React Use API
  • Introduction
  • Usage
    • Getting Started
    • Advanced Usage
      • List API and Pagination
      • Request Control
      • Data Processing
      • Side-Effect Dependencies
      • Watch option
    • TypeScript
  • API
    • useApi
    • State
    • Request Function
    • ApiProvider
    • injectSSRHtml
    • loadApiCache
  • Server Side Rendering
    • SSR Settings
    • Examples
      • Real World Examples
      • With Ant Design
Powered by GitBook
On this page
  • Code
  • First State (before calling API)
  • Full State

Was this helpful?

  1. API

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.

PrevioususeApiNextRequest Function

Last updated 5 years ago

Was this helpful?