Last active
December 17, 2023 21:32
-
-
Save christianvmm/14d14ada0c47a22568801cf7b120c7cb to your computer and use it in GitHub Desktop.
Generics in components. React Typescript
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
| // 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