Skip to content

Instantly share code, notes, and snippets.

@OlegLustenko
Created November 4, 2023 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OlegLustenko/21fcc9f3d0fb02fc1abb5f4dddd26928 to your computer and use it in GitHub Desktop.
Save OlegLustenko/21fcc9f3d0fb02fc1abb5f4dddd26928 to your computer and use it in GitHub Desktop.
With Props Server Component
import React, { ComponentType } from 'react';
type anyFIXME = any;
export function withAsyncProps<OriginalProps, NewProps>(
input: (props: OriginalProps) => Promise<NewProps>,
) {
return (
BaseComponent: ComponentType<OriginalProps & NewProps>,
): ComponentType<Omit<OriginalProps, keyof NewProps> & Partial<NewProps>> => {
return async (props: anyFIXME) => {
const additionalProps = await input(props);
return (
<BaseComponent
{...props}
{...additionalProps}
/>
);
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment