Skip to content

Instantly share code, notes, and snippets.

@sbtnh
Created January 22, 2019 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbtnh/b08b101e7f1b74379b4d4806b793cd27 to your computer and use it in GitHub Desktop.
Save sbtnh/b08b101e7f1b74379b4d4806b793cd27 to your computer and use it in GitHub Desktop.
React generic component with TypeScript
/** 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