You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
keyValue is typed as a string and won't be type-checked. Also it limits supported data structures, for example, I wouldn't be able to pass a tuple or a map. If we used getValue(item: T): string; it would be type safe and work for any kind of data structure. It should also probably be called getLabel if the result will be displayed in the UI. It's more clear when value is used for IDs which don't appear in the UI and label for things which do.
To keep it clear and consistent, I suggest prefixing functions that get called when a certain event happens with on. Like onClick, onSelect I would name it onSearch
Drop items prop
I would keep props to a minimum so the component is easy to use. It was unclear to me on how I was supposed to use the component since it includes both search and items. Sure, I could try read the docs, but it's even better if we can avoid the confusion in the first place. In case we want synchronous behavior without fetching results from the network, we can still use the same search API:
Use generics in order to return correct types
onSelect?(suggestion: string): void;
suggestion
parameter has incorrect type. In case of auto tagging, it has a type ofITagUi
, and not a string.At the
Autocomplete
component level, we don't know the types of objects and should use generics in order for types to be resolved correctly:Replace
keyValue
with a functionkeyValue
is typed as a string and won't be type-checked. Also it limits supported data structures, for example, I wouldn't be able to pass a tuple or a map. If we usedgetValue(item: T): string;
it would be type safe and work for any kind of data structure. It should also probably be calledgetLabel
if the result will be displayed in the UI. It's more clear whenvalue
is used for IDs which don't appear in the UI and label for things which do.Better type definition for
listItemTemplate
listItemTemplate?(value: any): any;
-->listItemTemplate?: React.ComponentType<{item: T}>;
Naming suggestion for
search
To keep it clear and consistent, I suggest prefixing functions that get called when a certain event happens with
on
. LikeonClick
,onSelect
I would name itonSearch
Drop items prop
I would keep props to a minimum so the component is easy to use. It was unclear to me on how I was supposed to use the component since it includes both
search
anditems
. Sure, I could try read the docs, but it's even better if we can avoid the confusion in the first place. In case we want synchronous behavior without fetching results from the network, we can still use the same search API:The text was updated successfully, but these errors were encountered: