Skip to content

Instantly share code, notes, and snippets.

@davidgilbertson
Last active April 18, 2021 01:10
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 davidgilbertson/018d68d6dd9605c1b8e3b98b0a5699b5 to your computer and use it in GitHub Desktop.
Save davidgilbertson/018d68d6dd9605c1b8e3b98b0a5699b5 to your computer and use it in GitHub Desktop.
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