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,
});
You have to use the lazy query hook:
const [ trigger, { data } ] = api.endpoints.getBuisnessAreas.useLazyQuery()
const onClick = () => {
trigger()
}