Created
November 4, 2023 11:14
-
-
Save OlegLustenko/21fcc9f3d0fb02fc1abb5f4dddd26928 to your computer and use it in GitHub Desktop.
With Props Server 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 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