Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

the-road-to-learn-react/use-data-api

Repository files navigation

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

About

Custom hook for React Components to fetch data from an API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.