Skip to content

spiko-tech/effect-react-query

Repository files navigation

effect-react-query

Integration between Effect and TanStack React Query.

Installation

npm install @effect-react-query
# or
bun add @effect-react-query
# or
pnpm add @effect-react-query

Quick Example

import { useEffectQuery, useEffectMutation } from "@effect-react-query";
import { Effect, Schema, Match } from "effect";

// Define typed errors
class NetworkError extends Schema.TaggedError<NetworkError>()("NetworkError", {
  message: Schema.String,
}) {}

// Use with queries
const query = useEffectQuery({
  queryKey: ["user", userId],
  queryFn: () => fetchUser(userId), // Effect<User, NetworkError>
});

// Use with mutations
const mutation = useEffectMutation({
  mutationFn: (data: CreateUserInput) => createUser(data),
  onError: Match.valueTags({
    NetworkError: (e) => toast.error(e.message),
  }),
});

// Type-safe error handling
if (query.error) {
  Match.valueTags(query.error, {
    NetworkError: (e) => console.log(e.message),
  });
}

Documentation

See the full API reference

About

Tanstack Query Effectful hooks

Resources

License

Stars

Watchers

Forks

Contributors