Skip to content
项目

关于

用于 React 组件从 API 获取数据的自定义 Hook。

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

useDataApi React Hook

Build Status Slack Greenkeeper badge NPM

Custom hook for React Components to fetch data from an API. Read more about it..

Example over here.

Installation

npm install use-data-api

Usage

Accepts as first argument an endpoint URL and as second argument an initial state for data. It returns as first item in an array an object which holds the data, isLoading and isError states, and the actual function to fetch the data (e.g. on a button click).

import React from 'react';

import useDataApi from 'use-data-api';

const AnyComponent = props => {
  const [{ data, isLoading, isError }, doFetch] = useDataApi(
    'http://hn.algolia.com/api/v1/search?query=redux',
    null,
  );

  ...
};

Contribute

  • git clone [email protected]:the-road-to-learn-react/use-data-api.git
  • cd use-data-api
  • npm install
  • npm run test

More

探索相关项目

加载中…