Skip to content

Instantly share code, notes, and snippets.

View perfectbase's full-sized avatar

Ravi perfectbase

View GitHub Profile
@perfectbase
perfectbase / await.tsx
Last active April 16, 2025 05:02
Await component for Next.js
import { Fragment, Suspense, type ReactNode } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
type AwaitProps<T> =
| {
promise: Promise<T>;
children: (data: T) => ReactNode;
fallback?: ReactNode;
errorComponent?: ReactNode | null;
}
@perfectbase
perfectbase / await.tsx
Last active April 18, 2025 21:47
Await component for tRPC with prefetch
/* eslint-disable @typescript-eslint/no-explicit-any */
import { type TRPCQueryOptions } from '@trpc/tanstack-react-query';
import { unstable_noStore } from 'next/cache';
import { Fragment, Suspense, type ReactNode } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { HydrateClient, prefetch as prefetchTRPC } from '@/trpc/server';
type AwaitProps<T> =
| {
promise: Promise<T>;