Last active
June 6, 2020 11:31
-
-
Save janjakubnanista/281740e1e8fba6a35a19c7b0bf7b6937 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
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