Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Created November 16, 2022 04:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save crutchcorn/3779e476d3afd119a59f2c940faada32 to your computer and use it in GitHub Desktop.
A TypeScipt type to add children to older React components that don't have children declared
import { ComponentType, PropsWithChildren } from "react";
import { Text } from "react-native";
import { Wrapper } from "aws-amplify-react-native";
// 🪄 This is the magic
type AddChildrenToComponent<T> = T extends ComponentType<infer P>
? ComponentType<PropsWithChildren<P>>
: never;
const WrapperWithChildren = Wrapper as AddChildrenToComponent<typeof Wrapper>;
export const YourComp = () => {
return (
<WrapperWithChildren>
<Text>Hello, world!</Text>
</WrapperWithChildren>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment