Skip to content

Instantly share code, notes, and snippets.

@cdaz5
Created August 12, 2022 14:42
Show Gist options
  • Save cdaz5/11e28996946759676b424d29968d67b4 to your computer and use it in GitHub Desktop.
Save cdaz5/11e28996946759676b424d29968d67b4 to your computer and use it in GitHub Desktop.
Explicitly pass a generic to a React component
const OPTIONS = [
{ value: 'rcube', label: 'Rubix Cube' },
{ value: 'headphones', label: 'Bose Headphones' },
{ value: 'mic', label: 'Mic' },
] as const;
const App = () => (
<Dropdown<typeof OPTIONS[number]> // generic explicitly passed
options={OPTIONS}
onSelection={(opt) => {
console.log(opt)
}}
/>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment