Use react query in table with sorting and filtering #1113
Replies: 3 comments 5 replies
-
You could just solve it with state:
and then just call please be aware that each query key has it's own "data", so if you put filtering / sorting options in the key, you will not get all the benefits of react-query. This has been outlined in the paginated queries section of the docs:
so for the pagination, |
Beta Was this translation helpful? Give feedback.
-
I think transformations are now currently best done with
you can also abstract that away in a custom hook. It looks like the next major version might have a |
Beta Was this translation helpful? Give feedback.
-
Is there a more effective approach available for this? |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm trying to use
react-query
with my existing Table component.The thing is, that I have a query to fetch some data. I'm passing an object with base config for sorting and pagination.
Then in the table component is a sort button in each column. I added
refetch
function to the sorting button, but I need to pass another object whereorder: 'DESC'
, which I cannot, since therefetch
doesn't have any configuration object.How would you approach something like this with
react-query
?This is a function which I use for sorting, where
fetchAction
was actually therefetch
from theuseQuery
hook.Same or similar problem would be with filters, where each filter has different payload, but I need the data to be connected. So when I fetch for all data with a
useQuery
hook, how can I fetch filtered data and still use the{ data } = useQuery(...)
from the hook?Is there a way to approach this with
react-query
?Thanks for any input! 🙏🏻
Beta Was this translation helpful? Give feedback.
All reactions