@ice.js/build-plugin-ice-request
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

plugin-ice-request

use request or useRequest in icejs.

Install

$ npm i --save build-plugin-ice-request

Add plugin to build.json:

{
  "plugins": [
    "build-plugin-ice-request"
  ]
}

Set runtime options to src/index.ts:

import { runApp } from 'ice';

const appConfig = {
  request: {
    // ref: https://github.com/axios/axios#request-config
    ...config,
    // ref: https://github.com/axios/axios#interceptors
    interceptors: {
      request: {
        onConfig: (config) => {},
        onError: (error) => {}
      },
      response: {
        onConfig: (config) => {},
        onError: (error) => {}
      },
    }
  }
};

runApp(appConfig);

Usage

request

import { request } from 'ice'

request('/api/repo')
  .then(res => console.log(res))
  .catch(err => console.log(err))

useRequest

import { useRequest } from 'ice'

const View = () => {
  const { loading, error, data, request } = useRequest({
    url: '/api/list',
    method: 'GET',
  })

  const list = data ? data.list : [];

  useEffect(() => {
    request();
  }, []);

  return (
    // do somethings
  )
}

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @ice.js/build-plugin-ice-request

Weekly Downloads

2

Version

2.0.1

License

MIT

Unpacked Size

18.8 kB

Total Files

13

Last publish

Collaborators

  • soocto