Skip to content

Instantly share code, notes, and snippets.

@christianvmm
Last active December 17, 2023 21:32
Show Gist options
  • Select an option

  • Save christianvmm/14d14ada0c47a22568801cf7b120c7cb to your computer and use it in GitHub Desktop.

Select an option

Save christianvmm/14d14ada0c47a22568801cf7b120c7cb to your computer and use it in GitHub Desktop.
Generics in components. React Typescript
// Definition
type ComponentProps<Generic1, Generic2> = {
prop1: Generic1
prop2: Generic2
}
export const Component = <T, T1>(props: ComponentProps<T, T1>) => {
const { prop1, prop2 } = props
return <></>
}
// Use
const App = () => {
return <Component <string, number> prop1="text" prop2={2} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment