Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.