Skip to content

Releases: htunnicliff/swr-openapi

v.5.6.0

12 Jan 17:44
Immutable release. Only release title and notes can be modified.
0821f9b

Choose a tag to compare

  • Fix config types for suspense support (#42) 37b2f8b

v5.5.2...v5.6.0

v5.5.2

12 Jan 01:40
Immutable release. Only release title and notes can be modified.
9c4b340

Choose a tag to compare

  • Remove unneeded npm ignore (#39) 06512f1
  • Replace biome with oxlint and prettier (#38) e072488
  • Bump preact from 10.28.0 to 10.28.2 5c66ea5
  • Bump vitest from 3.2.4 to 4.0.16 (#35) 2aa6db1
  • Update pnpm and pin actions 8f384ab
  • Bump @types/lodash from 4.17.20 to 4.17.23 e8d5a31
  • Bump swr from 2.3.6 to 2.3.8 7f9c2f2
  • Add boilerplate dependabot configuration 9349bbb

v5.5.1...v5.5.2

v5.5.1

26 Dec 22:50
16149b3

Choose a tag to compare

Full Changelog: v5.5.0...v5.5.1

v5.5.0

10 Dec 19:26
cbbd3ee

Choose a tag to compare

5.5.0

v5.0.0

11 Sep 18:37

Choose a tag to compare

Overview of Changes

  • Rewrote APIs to use latest openapi-fetch types.
  • Added useImmutable and useMutate hooks.
  • Broke apart createHooks into separate builder functions.
  • Added support for optional fetch option arguments.
  • Wrote comprehensive tests for both runtime behavior and type checking.
  • Wrote brand-new README documentation detailing new APIs.

See how to migrate from v4 below 👇

Breaking Changes

  • Removed CommonJS support (now ESM-only).
  • Removed global configuration function.
  • Replaced createHooks with separate builder functions.
  • Replaced matchKeyComparator with useMutate.
  • Renamed and refactored RequestTypesTypesForRequest.
  • Fixed internal types that broke from breaking changes in openapi-fetch.

Migration from v4

Imports

Replace createHooks calls with createQueryHook, createInfiniteHook, and createImmutableHook as needed.

import createClient from "openapi-fetch";
-import { createHooks } from "swr-openapi";
+import { createQueryHook, createInfiniteHook } from "swr-openapi";

const client = createClient(/* */);

-const { 
-  use: useSandwich, 
-  useInfinite: useSandwichInfinite 
-} = createHooks(client, "sandwich-api");
+export const useSandwich = createQueryHook(client, "sandwich-api");
+export const useSandwichInfinite = createInfiniteHook(client, "sandwich-api");

Fetch Options

For requests made that don't have required fetch options (like a path parameter), feel free to remove empty init arguments like this, as they are no longer required!

-const { data } = useQuery('/some/path', {});
+const { data } = useQuery('/some/path');

Key Matchers

Remove applySwrOpenApiConfiguration and define a useMutate hook using createMutateHook:

import createClient from "openapi-fetch";
import { isMatch } from "lodash";
-import { applySwrOpenApiConfiguration, createHooks } from "swr-openapi";
+import { createMutateHook } from "swr-openapi";

const client = createClient(/* */);

-applySwrOpenApiConfiguration({ matchKeyComparator: isMatch });

-export { matchKey } = createHooks(client, "unique-prefix");
+export const useMutate = createMutateHook(
+  client,
+  prefix,
+  isMatch
+);

To replace matchKey in consumers, call useMutate and invoke the callback like this:

-import { useSWRConfig } from "swr";
-import { matchKey } from "./api-clients";
+import { useMutate } from "./api-clients";  

function MyComponent() {
  // ...

-  const { mutate } = useSWRConfig();
+  const mutate = useMutate();

  const save = async () => {
    // ...
    await mutate(
-     matchKey("/some/path", { params: { query: { some: "item" } } }),
+     ["/some/path", { params: { query: { some: "item" } } }],
      { some: "data" },
    );
  };

  // ...
}

ESM in Next.js

If using Next.js in a non-ESM project, add swr-openapi to the transpilePackages array in your Next.js config file. This should take care of transpilation automatically, as well as transforming in Jest (if you use next/jest).


v4.1.2...v5.0.0

v5.0.0-rc.15

11 Sep 17:26

Choose a tag to compare

v5.0.0-rc.15 Pre-release
Pre-release
  • Add links to swr documentation 936306b

v5.0.0-rc.14...v5.0.0-rc.15

v5.0.0-rc.8

10 Sep 16:21

Choose a tag to compare

v5.0.0-rc.8 Pre-release
Pre-release

v5.0.0-rc.7

10 Sep 15:58

Choose a tag to compare

v5.0.0-rc.7 Pre-release
Pre-release

v5.0.0-rc.6

10 Sep 15:50

Choose a tag to compare

v5.0.0-rc.6 Pre-release
Pre-release

v5.0.0-rc.5...v5.0.0-rc.6

v5.0.0-rc.14

10 Sep 23:12

Choose a tag to compare

v5.0.0-rc.14 Pre-release
Pre-release
  • Include prefix in debug values b9bcba5

v5.0.0-rc.13...v5.0.0-rc.14