1.2.0 • Published 3 years ago

react-use-fetch-hooks v1.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

react-use-fetch

Fetch with simple loading container.

npm package Dependencies Status Package Size

Getting started

Install with NPM:

$ npm install react-use-fetch-hooks

Usage

Live Demo CodeSandbox

With this component, you can simply manage the loading process when you send fetch requests. You can control the loading process of each fetch request separately. You don't need to write extra code for this.

Example

When you send the fetch request, the field inside the <Loading></Loading> tags is blocked and becomes accessible again when the request is done or error.

import React from 'react';
import useFetch from 'react-use-fetch-hooks';
import 'react-use-fetch-hooks/dist/index.css';

function App() {
  const [Fetch, Loading] = useFetch(
    'REQUEST URL',
    'REQUEST OPTIONS',
  );
  return (
  <div>
    <Loading>
      <button type="button" onClick={() => Fetch()}></button>
    </Loading>
  </div>
  );
};

export default App;

Properties

Descriptions and configuration settings for component properties.

useFetch
PropertyTypeRequiredDefaultDescription
urlstringnonullFetch request uri.
requestOptionsstringnonullFetch request options.
Fetch
PropertyTypeRequiredDefaultDescription
dataobjectnonullFetch body.
Loading
PropertyTypeRequiredDefaultDescription
darkboolnofalseUse dark theme loading overlay.
classNamestringnonullLoading container custom class.
buttonboolnofalseFetch loading only button.

Author

Barış Ateş

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago