react-use-network

0.0.1 • Public • Published

useNetwork

A simple React hook to be wrapped around API calls for simple retries and queuing. [WIP]

Usage

Initalize Hook with Options

import createUseNetwork from 'use-network';
// hooks/use-network.js;

export default createUseNetwork({
 maxRetries: [Int, default = 3], // Changing this to null will make the hook constantly attempt to reconnect, otherwise, none of the calls will be attempted again until another network call is made, which will restart the retry process.
 queue: [Boolean, default = true]
});

Component

import useNetwork from 'hooks/use-network.js';
 
...[some arbitrary component-related code here]

const { execute, error, isLoading } = useNetwork(
  async () => {
    await (make API call here)
  }
)

...[some arbitrary component-related code here]

Readme

Keywords

none

Package Sidebar

Install

npm i react-use-network

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

3.47 kB

Total Files

7

Last publish

Collaborators

  • nathanielopdev