Created
January 22, 2019 18:07
-
-
Save sbtnh/b08b101e7f1b74379b4d4806b793cd27 to your computer and use it in GitHub Desktop.
React generic component with TypeScript
This file contains 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
/** Generic component */ | |
type MyComponentProps<T> = { data: T[] } | |
class MyComponent<T> extends React.Component<MyComponentProps<T>, any> { } | |
/** Usage */ | |
<MyComponent<number> data={[12, 15, 18]} /> | |
<MyComponent<string> data={["one", "two", "three"]} /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment