Effect CommunityEC
Effect Community8mo ago
5 replies
JimZer

Integrating Effect's HttpApi with Tanstack Query for Smooth Backend Queries

Hey guys, I'm diving more and more into Effect and I just wanted to share so helpers I use to smoothly integrate the HttpApi derived client with Tanstack Query.

Here is a gist: https://gist.github.com/jimzer/5adfb462172a100e7619f9566bc9a46c


And here is some utilization example:

const login = useEffectMutation("auth", "usernameLogin", {
    onSuccess: () => {
        toast.success("Login successful");
        navigate({ to: "/" });
    },
    onError: (error) => {
        toast.error(`Login failed: ${JSON.stringify(error)}`);
    },
});

const me = useEffectQuery("auth", "me", {});


It lets you query you backend using just the group and handler name.

Hope it can be useful to some of you : )
Was this page helpful?