I try to pass isLoading state to button prop when click button which trigger refetch function from useQuery, and it doesn't work (maybe because it re-render component and when component render isLoading is false). I wonder how i can make it works?
const MainPage: React.FC = () => {
const {data, isLoading, error, refetch} = useQuery<any>(
["getCity"],
() => fetchCities(),
{
enabled: false,
}
)
return (
<div>
<div>
{JSON.stringify(data)}
</div>
<Button
loading={isLoading} // always false. Need to be true when start refetch and false by the end refetch
label="get_cities"
onClick={() => refetch()}
>
</Button>
</div>
)
}
export default MainPage;