Accept an `action` property in the `items` item object
When all of the select items have different actions, it's annoying having to define values and then do a switch on them in the onSelect handler. Would be nicer to be able to define the actions directly.
Since onSelect returns the current item, why don't you do this:
const items = [{label: 'Unicorn', value: 'unicorn', action: () => {}}];
const handleSelect = item => {
item.action();
};
<SelectInput items={items} onSelect={handleSelect}/>;
Feels cleaner than handling it in this module.
@kevva That works too. Good idea! Although, I still think action() should be called by default if defined, as your solution was not obvious, and having it called by default would be a nice convenience and also make it clear as it would be documented in the readme.
In my mind, @kevva's solution is more idiomatic React
It should at least be documented in the readme.