Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Redux-toolkit-query Manually on button click

I am using Redux-toolkit-query (RTK Query) to fetch data from the server. Now, I want to call my query on button click, not automatically. I tried this but it's not working.

const { data, refetch } = useGetBusinessAreasQuery({
    enable: false,
    refetchOnWindowFocus: false,
    manual: true,
    refetchOnReconnect: false,
  });
like image 872
Andaman Avatar asked Feb 01 '26 21:02

Andaman


1 Answers

You have to use the lazy query hook:

const [ trigger, { data } ] = api.endpoints.getBuisnessAreas.useLazyQuery()

const onClick = () => {
  trigger()
}
like image 146
Rashomon Avatar answered Feb 03 '26 11:02

Rashomon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!