Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 635 Bytes

xs.md

File metadata and controls

35 lines (27 loc) · 635 Bytes

English | 简体中文

xs

Remote data fetching solution for Promise-based Ajax request chain

Quick Start

import {xs} from 'xswr'
import service from './service'

const fetchAssetInfo() {
  xs("/api/account", fetcher, {
    staleWhileRevalidateMS: 1000,
    poolingInterval: 1000,
  }).then(account => {
    const {assetsId} = account.data

    return xs(["/api/assets", {id: assetsId}], (url, params) => {
      return fetch(url, params)
    })
  }).then(assets => {
    // handle assets
  }).catch(err => {
    // handle error
  })
}

Usage

const promise = xs(key, fetcher, config)