TanStackT
TanStack2y ago
3 replies
significant-gray

refetching isnt working

  const userHoldings = useQuery({
    queryKey: ['userHoldings', searchParams.get('selected')],
    queryFn: () => getUserHoldings(searchParams.get('selected') as string),
  })
  const query = useQuery({
    queryKey: [
      'usersWithHoldings',
      searchParams.get('users'),
      searchParams.get('search'),
    ],
    queryFn: () =>
      getHoldings(
        searchParams.get('users') || '',
        searchParams.get('search') || ''
      ),
  })


// THOSE ABOVE ARE THE QUERIES THAT I GET DATA FROM


  const handleItemAssigner = async (e: FormEvent<HTMLFormElement>) => {
    e.preventDefault()
    if (!assetId) return
    const payload = {
      userId: searchParams.get('selected'),
      takenDate: new Date().toISOString(),
    }
    const res = await AxiosInstance.patch(`/asset/${assetId}`, payload)
    if ([200, 201].includes(res.status)) {
// THIS DOES ABSOLUTELY NOTHING
      queryClient.invalidateQueries({
        queryKey: ['usersWithHoldings', 'userHoldings'],
      })
    } else {
      alert('Something went wrong')
    }
  }


It doesnt work with useMutation also, where is my mistake, what im doing wrong
Was this page helpful?