Created
August 12, 2022 14:42
-
-
Save cdaz5/11e28996946759676b424d29968d67b4 to your computer and use it in GitHub Desktop.
Explicitly pass a generic to a React component
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
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