redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Refetch without parameters

Open YuriyDyachkov opened this issue 3 years ago • 2 comments

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(?)

YuriyDyachkov avatar Jul 30 '22 10:07 YuriyDyachkov

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

spacepolice10 avatar Aug 18 '22 07:08 spacepolice10

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.

phryneas avatar Aug 18 '22 13:08 phryneas