3.0.3 • Published 4 years ago

use-abortable-fetch v3.0.3

Weekly downloads
1,067
License
MIT
Repository
github
Last release
4 years ago

use-abortable-fetch

Build Status

React hook that does a fetch and aborts when the components is unloaded or a new fetch request is started.

Installation

npm install use-abortable-fetch or yarn add use-abortable-fetch

Example usage:

import React from 'react';
import useAbortableFetch from 'use-abortable-fetch';

const ChuckNorrisJoke = () => {
  const { data, loading, error, abort } = useAbortableFetch(
    '//api.icndb.com/jokes/random/?limitTo=[nerdy]&escape=javascript'
  );

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;
  if (!data) return null;

  return <div>Joke: {data.value.joke}</div>;
};

export default ChuckNorrisJoke;

See this CodeSandbox for a running example.

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.6.14

5 years ago

2.6.13

5 years ago

2.6.12

5 years ago

2.6.8

5 years ago

2.6.11

5 years ago

2.6.7

5 years ago

2.6.6

6 years ago

2.6.5

6 years ago

2.6.4

6 years ago

2.6.3

6 years ago

2.6.2

6 years ago

2.6.0

6 years ago

2.4.0

6 years ago

2.3.0-0

6 years ago

2.2.0

6 years ago

2.0.0

6 years ago

0.5.2

6 years ago

0.5.0

6 years ago

0.3.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago