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.4k
Weekly
33M
Open issues
18
Bundle
~15 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
  • 33M weekly downloads. Battle tested
  • First-class TypeScript definitions
  • MIT licensed

Considerations

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

FAQs

Alternatives & similar libraries