Created
July 30, 2025 16:18
-
-
Save alexanderson1993/6916cf7782843bc5be62b47c8e3c0780 to your computer and use it in GitHub Desktop.
React Await Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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