Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Releases: CharlesStover/fetch-suspense

1.2.0

30 Jul 03:20
Compare
Choose a tag to compare

New Features ✨

  • An options flag now enables metadata for the request in addition to the response. (Thanks @mjpsyapse!)
const { contentType, response, status } = useFetch(
  '/some-path',
  { method: 'POST' },
  { metadata: true },
);

v1.1.0

12 Apr 17:37
fbb4e4b
Compare
Choose a tag to compare

New Feature

  • createUseFetch allows you to create a useFetch hook based on your own Fetch API implementation. #7 #8 #9 (Thanks @tomchentw!)
import { createUseFetch } from 'fetch-suspense';
import myFetchApi from 'my-fetch-package';
import React, { Suspense } from 'react';

// Create a useFetch hook using one's own Fetch API.
// NOTE: useFetch hereafter refers to this constant, not the default export of
//   the fetch-suspense package.
const useFetch = createUseFetch(myFetchApi);

// This fetching component will be delayed by Suspense until the fetch request
//   resolves.
// The return value of useFetch will be the response of the server.
const MyFetchingComponent = () => {
  const data = useFetch('/path/to/api', { method: 'POST' });
  return 'The server responded with: ' + data;
};

// The App component wraps the asynchronous fetching component in Suspense.
// The fallback component (loading text) is displayed until the fetch request
//   resolves.
const App = () => {
  return (
    <Suspense fallback="Loading...">
      <MyFetchingComponent />
    </Suspense>
  );
};

Bug Fix