CR

Cross Fetch

cross-fetch

Universal WHATWG Fetch API for Node, Browsers and React Native

Data Fetching
fetch
http
url
promise
async
await
isomorphic
universal
node
react
Stars
1.7k
Weekly
0
Open issues
27
Bundle
~60 kB

Installation

npm install cross-fetch

Code example

import { useCrossFetch } from "cross-fetch";

export function Example() {
  const { data, isLoading, error } = useCrossFetch({
    queryKey: ["example"],
    queryFn: () => fetch("/api/example").then((r) => r.json()),
  });

  if (isLoading) return <p>Loading…</p>;
  if (error) return <p>Could not load data.</p>;
  return <pre>{JSON.stringify(data, null, 2)}</pre>;
}

Pros & cons

Pros

  • Actively maintained by Leonardo Quixada
  • 0 weekly downloads. Battle tested
  • First-class TypeScript definitions
  • MIT licensed

Considerations

  • Adds roughly ~60 kB to your bundle
  • Needs client-only rendering in SSR frameworks
  • 27 open issues on GitHub

FAQs

Alternatives & similar libraries