Last active
April 18, 2021 01:10
-
-
Save davidgilbertson/018d68d6dd9605c1b8e3b98b0a5699b5 to your computer and use it in GitHub Desktop.
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
const Select = <IdType extends string>(props: { | |
options: Array<{ | |
id: IdType; | |
name: string; | |
}>; | |
selectedItemId?: IdType; | |
onSelect: (id: IdType) => void; | |
}) => ( | |
<select | |
value={props.selectedItemId ?? ''} | |
onChange={e => props.onSelect(e.target.value as IdType)} | |
> | |
{props.options.map(option => ( | |
<option key={option.id} value={option.id}> | |
{option.name} | |
</option> | |
))} | |
</select> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment