Skip to content

feats(transform):#208

Merged
danybeltran merged 1 commit intomasterfrom
feats/transform
Jul 27, 2025
Merged

feats(transform):#208
danybeltran merged 1 commit intomasterfrom
feats/transform

Conversation

@danybeltran
Copy link
Copy Markdown
Member

@danybeltran danybeltran commented Jul 27, 2025

Features: transform

useFetch.data will now be inferred from the transform function's return type if present

Example:

import useFetch, { fetchOptions } from "http-react";

// You can create reusable fetch options with the fetchOptions fn
const charactersFetch = fetchOptions({
  url: "https://rickandmortyapi.com/api/character",
  key: ["characters"],
  default: { results: [] } as { results: { id: number }[] },
  transform(data) {
    return data.results.find((character) => character.id === 1)!;
  },
});

function Todos() {
  // Data will be inferred as { id: number }
  const { data } = useFetch(charactersFetch);

  return (
    <div>
      <pre>{JSON.stringify(data, null, 2)}</pre>
    </div>
  );
}

useFetch.data will now be inferred from transform's return type is present
@danybeltran danybeltran merged commit a2d0985 into master Jul 27, 2025
2 checks passed
@danybeltran danybeltran deleted the feats/transform branch July 27, 2025 16:28
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