Skip to content

Conversation

@prescottprue
Copy link

Changes

Adds createMutationHook which is a function that creates a typesafe wrapper around useSWRMutation hook like so:

import createClient from "openapi-fetch";
import type { paths } from "./my-openapi-3-schema"; // generated types

const client = createClient<paths>({ baseUrl: "https://my-api.com" });
const useMutation = createMutationHook(client, "my-api");

function MyComponent() {
  const { trigger, data, isMutating } = useMutation("/users", "post");

  return (
    <button
      disabled={isMutating}
      onClick={() => {
        trigger({ body: { name: "New User" } });
      }}
    >
      Create User
    </button>
  );
}

Currently this does not support a custom fetcher (as the SWR hook does) so we might want to add that before merging

What does this PR change? Link to any related issue(s).

How to Review

How can a reviewer review your changes? What should be kept in mind for this review?

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)
  • Support custom fetcher

@prescottprue prescottprue requested a review from a team as a code owner December 18, 2025 19:36
@prescottprue prescottprue requested a review from drwpow December 18, 2025 19:36
@netlify
Copy link

netlify bot commented Dec 18, 2025

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit b2f2ead

@changeset-bot
Copy link

changeset-bot bot commented Dec 18, 2025

⚠️ No Changeset found

Latest commit: b2f2ead

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -1,5 +1,11 @@
# swr-openapi

## 5.5.0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure if this and the version bump were meant to be done manually or if there is an automated process - I just saw the CI message about the changelog not being updated so I did it manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant