Migrated from v4 to v5, don't know how to use it without onSucess
I have tried removing the onSuccess as I should, and then including it in the an independent useEffect, but the content renders for a split second and disappears.
6 Replies
solid-orange•2y ago
your
[query, setQuery]
is derived state that you don't need to storesolid-orange•2y ago
please read: https://react.dev/learn/you-might-not-need-an-effect
You Might Not Need an Effect – React
The library for web and native user interfaces
exotic-emeraldOP•2y ago
I made the following changes:
I removed the query, setQuery state.
I removed the useEffect
I then added this:
const query = router.query.desde && router.query.hasta && router.query.tienda
Its now working correctly. Would you suggest adding anything else?
provincial-silver•2y ago
keepPreviousData
also changed in v5, you have to use placeholderData :keepPreviousData
exotic-emeraldOP•2y ago
yeah, figured that one out
const getFacturas = useQuery({
queryKey: ['facturas', query],
queryFn: () =>
axiosFetcherFacturasBetweenDates(
'/api/analisis-facturas-api',
desde,
hasta,
tienda
),
enabled: !!query,
placeholderData: keepPreviousData,
refetchOnWindowFocus: false
})
thanks
Sorry to bother again...
I am indeed stuck with this one:
i have tried many different ways and i cant seem to make the search button work without the onSucess. Any idea how can i restructure this code?
anybody here?
rival-black•2y ago
Why are you even doing this?
Just delete it