@ergenekonyigit/usefetch
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

useFetch

React hook for fetching json data

Note: This is using the new React Hooks API

You'll need to install react, react-dom, etc at ^16.8.0 or above

Install

yarn add useFetch

Usage

import useFetch from 'useFetch';

function MyComponent() {
  let value = useFetch('https://api.github.com/repos/ergenekonyigit/nemene');

  // value = {
  //   "id": 115508797,
  //   "node_id": "MDEwOlJlcG9zaXRvcnkxMTU1MDg3OTc=",
  //   "name": "nemene",
  //   "full_name": "ergenekonyigit/nemene",
  //   "private": false,
  //   "owner": {
  //     "login": "ergenekonyigit",
  //     "id": 7110136,
  //     "node_id": "MDQ6VXNlcjcxMTAxMzY=",
  //     "avatar_url": "https://avatars3.githubusercontent.com/u/7110136?v=4",
  //     "gravatar_id": "",
  //     "url": "https://api.github.com/users/ergenekonyigit",
  //     "html_url": "https://github.com/ergenekonyigit",
  //     ...
  // }

  return value.loading ? (
      <div>Loading...</div>
    ) : (
      <pre>{JSON.stringify(value.data, null, 2)}</pre>
    );
}

Readme

Keywords

Package Sidebar

Install

npm i @ergenekonyigit/usefetch

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

3.71 kB

Total Files

6

Last publish

Collaborators

  • ergenekonyigit