use-api
v1.0.2
Published
[![Build Status](https://travis-ci.org/the-road-to-learn-react/use-data-api.svg?branch=master)](https://travis-ci.org/the-road-to-learn-react/use-data-api) [![Slack](https://slack-the-road-to-learn-react.wieruch.com/badge.svg)](https://slack-the-road-to-l
Downloads
7
Readme
useApi React Hook
Custom hook for React Components to fetch data from an API. Read more about it..
Installation
npm install use-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 useApi from 'use-api';
const AnyComponent = props => {
const [{ data, isLoading, isError }, doFetch] = use-api(
'http://hn.algolia.com/api/v1/search?query=redux',
null,
);
...
};
Contribute
git clone
cd use-api
npm install
npm run test