Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save janjakubnanista/281740e1e8fba6a35a19c7b0bf7b6937 to your computer and use it in GitHub Desktop.
Save janjakubnanista/281740e1e8fba6a35a19c7b0bf7b6937 to your computer and use it in GitHub Desktop.
export function Select<T>({ items, value, idFromValue }: SelectProps<T>) {
// selectedId will be a string/number value that we can use to identify the selected item
const selectedId = value === undefined ? undefined : idFromValue(value);
return <div>
{items.map(item => {
const id = idFromValue(item);
// selected will now be true for values with matching IDs
const selected = id === selectedId;
return <div key={id}/>;
})}
</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment