Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/the-road-to-learn-react/use-data-api
Custom hook for React Components to fetch data from an API.
https://github.com/the-road-to-learn-react/use-data-api
react react-data react-fetch reactjs
Last synced: 3 months ago
JSON representation
Custom hook for React Components to fetch data from an API.
- Host: GitHub
- URL: https://github.com/the-road-to-learn-react/use-data-api
- Owner: the-road-to-learn-react
- License: mit
- Created: 2019-06-05T19:09:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-12T08:29:44.000Z (over 4 years ago)
- Last Synced: 2024-07-10T16:55:11.211Z (4 months ago)
- Topics: react, react-data, react-fetch, reactjs
- Language: JavaScript
- Homepage: https://www.robinwieruch.de/react-hooks-fetch-data
- Size: 119 KB
- Stars: 242
- Watchers: 7
- Forks: 20
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# useDataApi React Hook
[![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-learn-react.wieruch.com/) [![Greenkeeper badge](https://badges.greenkeeper.io/the-road-to-learn-react/use-data-api.svg)](https://greenkeeper.io/) ![NPM](https://img.shields.io/npm/l/use-data-api.svg)
Custom hook for React Components to fetch data from an API. [Read more about it.](https://www.robinwieruch.de/react-hooks-fetch-data/).
[Example over here.](https://github.com/the-road-to-learn-react/react-hooks-introduction/blob/master/src/useDataApiHook-external-example/index.js)
## 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
* [Publishing a Node Package to NPM](https://www.robinwieruch.de/publish-npm-package-node/)
* [Node.js Testing Setup](https://www.robinwieruch.de/node-js-testing-mocha-chai/)
* [React Testing Setup](https://www.robinwieruch.de/react-testing-tutorial/)