Skip to content

Instantly share code, notes, and snippets.

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
What would you like to do?
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 (
<Text>Hello, world!</Text>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment