Skip to content
Custom hook for React Components to fetch data from an API.
Branch: master
Clone or download
Latest commit 20acb97 Jun 5, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src first commit Jun 5, 2019
.babelrc first commit Jun 5, 2019
.gitignore first commit Jun 5, 2019
.npmignore first commit Jun 5, 2019
.prettierrc first commit Jun 5, 2019
.travis.yml first commit Jun 5, 2019
LICENSE first commit Jun 5, 2019
README.md ad example Jun 5, 2019
package-lock.json first commit Jun 5, 2019
package.json bump version Jun 5, 2019
webpack.config.js first commit Jun 5, 2019

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 git@github.com:the-road-to-learn-react/use-data-api.git
  • cd use-data-api
  • npm install
  • npm run test

More

You can’t perform that action at this time.