@pendant/api-react
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

api-react

快速请求 CODING OPEN API

Usage

import { setConfig, useFetchApi } from '@pendant/api-react';

setConfig({ clientId: '1234565' });

const ProjectListDemo = () => {
  const { response, error } = useFetchApi('DescribeCodingProjects', query);

  if (error || response?.Error) {
    return <>获取数据错误</>
  }

  if (response?.Data?.ProjectList instanceof Array) {
    return response?.Data?.ProjectList.map(project => <div>{project.Name}<div>)
  }

  return <>loading</>;
}

export default ProjectListDemo;

Api

setConfig

设置 api-react 的配置

{
  clientId: string;
  fetch?: Parameters<typeof fetch>;
}
参数 说明 类型 默认值
clientId 客户端 ID string -
fetch fetch 的默认参数[RequestInfo | URL, { headers: RequestInit['headers'] }],在发送请求的时候会合并到 参数里面。 Parameters -

fetchApi

函数式使用 fetchApihooks 使用 useFetchApi .

fetchApi('DescribeCodingProjects', query).then((res) => console.log(res));
const { response, error } = useFetchApi('DescribeCodingProjects', query);
参数 说明 类型 默认值
action 需要调用的业务 id string -
query 请求参数 Object -

getContext

获取应用的上下文信息

const { accessToken, apiUrl } = await getContext();

Readme

Keywords

none

Package Sidebar

Install

npm i @pendant/api-react

Weekly Downloads

12

Version

0.0.6

License

MIT

Unpacked Size

7.53 kB

Total Files

14

Last publish

Collaborators

  • linkang
  • yvonneqi
  • amosfu
  • chenjingjie