hsuanyi-chou / shadcn-ui-expansions

More components built on top of shadcn-ui.
https://shadcnui-expansions.typeart.cc/
MIT License
868 stars 38 forks source link

Usage with react-query / trpc #24

Open ZionLG opened 8 months ago

ZionLG commented 8 months ago

currently, I dont think its possible to use search with react-query / trpc with how the useSearch option works. would appreciate if you can make an example with it, thanks!

fitimbytyqi commented 3 months ago

@hsuanyi-chou +1

I believe onSearch should not handle the fetching logic but rather just pass the debounced search value and leave the developer to handle it himself.

In React Query's case, onSearch should only be used to set a state in the parent level which changes the queryKey and therefore, fresh data is passed into the multiselect.

hsuanyi-chou commented 3 months ago

There's a onSearch prop. I think you can change the queryKey here.

fitimbytyqi commented 3 months ago

onSearch expects a promise as return type.

I might be wrong though but an example with tanstack query would be nice to showcase its usage.

hsuanyi-chou commented 3 months ago

Sorry, my bad. I forgot that I need to update the options.

Maybe lazy query can do the trick.

In my project the multiple selector which is working with apollo client, I use the lazy query to search the value.

fitimbytyqi commented 3 months ago

I mean, I can set a state when onSearch executes on this implementation but its expecting me to return a promise and I only want to do something to the parent.

hsuanyi-chou commented 3 months ago

Let me clarify it: You expect to do something when input value changed?

If it does, there's a inputProps prop. You can use onChange to do something.

demo

fitimbytyqi commented 3 months ago

@hsuanyi-chou I tried to add an implementation with trpc, even though im passing the options correctly, I get an empty indicator in the options.

Screenshot 2024-06-28 at 11 29 01

Screenshot 2024-06-28 at 11 30 25
hsuanyi-chou commented 2 months ago

I tried this in the async search demo. It shows options correctly.🤔

image

image

image

Sorry for the late response. I was on vacation last week.