redux-toolkit
redux-toolkit copied to clipboard
Refetch without parameters
Hello, I have a paginated table in my application that is controlled on the backend. The table can be downloaded in xlsx format. Before downloading, I want to do a refetch without parameters. Since I need the complete table. Can I do it somehow?
const { data, refetch } = useGetTableQuery({
page: pageNumber,
pageSize: pageSizeNumber,
sorting,
tab,
});
refetch(?)
Hi. Can't you just store the whole set of args as a local state like
const [args, setArgs] = useState({
page: pageNumber,
pageSize: pageSizeNumber,
sorting,
tab,
})
const {data} = useGetTableQuery(args)
and then when you want to refetch data you can just pass default args to state and rtk query hook will automatically trigger refetching. Hope it helps
Also, you can solve it with useLazyQuery — https://redux-toolkit.js.org/rtk-query/api/created-api/hooks#uselazyquery
refetch would always just refetch with the parameters that you have set there. If you want to fetch that with other parameters, you would need to reset your parameters there.