Is it possible to make the onSuccess function in React Query trigger a fetch for the ‘products’ query even if it has not been fetched or cached before
import { useMutation, useQueryClient } from “@tanstack/react-query”; import api from “./Api”; export const usePostProduct = () => { const qc = useQueryClient(); return useMutation({ mutationFn: async (newProduct) => { const res = await api.post(“/products”, newProduct); return res.data; }, onSuccess: () => { qc.refetchQueries([“products”]); }, }); }; I have two pages: All Products and Upload Product. […]
How can all APIs be refreshed in a React component when any action is triggered?
import AppTextInput from ‘@/components/form-fields/AppTextInput’; import Iconify from ‘@/components/iconify/Iconify’; import AppButton from ‘@/components/templates/AppButton’; import AppDataGrid from ‘@/components/templates/AppDataGrid’; import AppLink from ‘@/components/templates/AppLink’; import AppPersona from ‘@/components/templates/AppPersona’; import TableSkeleton from ‘@/components/templates/AppTable/TableSkeleton’; import AppTag from ‘@/components/templates/AppTag’; import AppTitle from ‘@/components/templates/AppTitle’; import { CACHE_KEY_AVAILABLE_PAYROLL, CACHE_KEY_GENERATED_PAYROLL, CACHE_KEY_PAYROLL_CYCLE_PAYRUN, CACHE_KEY_POSTED_PAYROLL, CACHE_KEY_PROCESSED_PAYROLL, PAYROLL_CYCLE_LOCK_ENDPOINT, PAYROLL_CYCLE_PAYRUN_ENDPOINT, PAYROLL_CYCLE_SIF_ENDPOINT, PAYROLL_EMP_BY_STATUS_ENDPOINT, } from ‘@/constants/payroll’; import useGetAll from ‘@/hooks/useGetAll’; import […]