3.0.3 • Published 3 years ago

use-abortable-fetch v3.0.3

Weekly downloads
1,067
License
MIT
Repository
github
Last release
3 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

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

4 years ago

2.6.14

4 years ago

2.6.13

4 years ago

2.6.12

4 years ago

2.6.8

4 years ago

2.6.11

4 years ago

2.6.7

4 years ago

2.6.6

4 years ago

2.6.5

5 years ago

2.6.4

5 years ago

2.6.3

5 years ago

2.6.2

5 years ago

2.6.0

5 years ago

2.4.0

5 years ago

2.3.0-0

5 years ago

2.2.0

5 years ago

2.0.0

5 years ago

0.5.2

5 years ago

0.5.0

5 years ago

0.3.0

5 years ago

0.1.1

5 years ago

0.1.0

6 years ago

0.0.1

6 years ago