Skip to content

Instantly share code, notes, and snippets.

@alexanderson1993
Created July 30, 2025 16:18
Show Gist options
  • Save alexanderson1993/6916cf7782843bc5be62b47c8e3c0780 to your computer and use it in GitHub Desktop.
Save alexanderson1993/6916cf7782843bc5be62b47c8e3c0780 to your computer and use it in GitHub Desktop.
React Await Component
import { Suspense, use, type ReactNode } from 'react';
// A component for unwraping promises inline, without needing to create a separate component.
function Async<T>({
data,
children,
}: {
data: Promise<T>;
children: (val: T) => ReactNode;
}) {
const val = use(data);
return children(val);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment