Last active
May 3, 2023 21:50
-
-
Save n4bb12/a0b7512e7571ca0117462f5553f19c48 to your computer and use it in GitHub Desktop.
Next.js 13 async server component wrapper
This file contains 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 { ReactElement } from "react"; | |
export type RenderResult<P> = ReactElement<P, any> | null; | |
export function serverComponent<P = {}>(fn: (props: P) => RenderResult<P> | Promise<RenderResult<P>>) { | |
return fn as unknown as (props: P) => RenderResult<P>; | |
} | |
// or | |
import { ReactNode } from "react"; | |
declare global { | |
namespace JSX { | |
type ElementType = keyof JSX.IntrinsicElements | React.ComponentType<any> | ((props: any) => ReactNode | Promise<ReactNode>); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment