tRPCttRPC
Powered by
PeformP
tRPC•13mo ago
Peform

trpc useError hook?

Hey, I have a hook which i use for fetching some data using trpc and I'm wondering if there is some sort of
useError
useError
so i can catch all of the errors for each query, in one variable?
or is the best way using the
error
error
property on each of the useQuery invocations?

Currently, if I want to display an error I'd have to make 3 separate variables and parse each of those in the if statement
if error
if error
at the bottom.
export const GuildProvider = ({ guildId, children, fetchChannels, fetchRoles }: Props) => {
    const isFetching = useIsFetching();
    const { data: guild } = api.guild.get.useQuery({
        guildId,
    });
    const { data: channels } = api.guild.channels.useQuery(
        {
            guildId,
        },
        { enabled: fetchChannels },
    );
    const { data: roles } = api.guild.get.useQuery(
        {
            guildId,
        },
        { enabled: fetchRoles },
    );

    if (isFetching) {
        return <CustomLoader />;
    }

    if (error) {
        return <div>Error fetching guild data: {error.message}</div>;
    }
export const GuildProvider = ({ guildId, children, fetchChannels, fetchRoles }: Props) => {
    const isFetching = useIsFetching();
    const { data: guild } = api.guild.get.useQuery({
        guildId,
    });
    const { data: channels } = api.guild.channels.useQuery(
        {
            guildId,
        },
        { enabled: fetchChannels },
    );
    const { data: roles } = api.guild.get.useQuery(
        {
            guildId,
        },
        { enabled: fetchRoles },
    );

    if (isFetching) {
        return <CustomLoader />;
    }

    if (error) {
        return <div>Error fetching guild data: {error.message}</div>;
    }
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

testing a trpc hook
SonSSon / ❓-help
4y ago
tRPC + cls-hooked
v1narthVv1narth / ❓-help
3y ago
TRPC 11 Classic React Query custom hook
Fitim BytyqiFFitim Bytyqi / ❓-help
10mo ago