T
TanStack4y ago
fair-rose

It was working fine with version v3*

I am migrating to react-query v4. On my machine it works also fine but not on remote server. Mutation function keeps stale state for some reason.
const [shouldDrop,setShouldDrop]=useState(false)

const mutations= useMutation(["id"],(data)=> {
console.log(shouldDrop) // expected to be true but it is false
return fetcher({url:"...", method: shouldDrop ? "DELETE":"PATCH", data })
})
const [shouldDrop,setShouldDrop]=useState(false)

const mutations= useMutation(["id"],(data)=> {
console.log(shouldDrop) // expected to be true but it is false
return fetcher({url:"...", method: shouldDrop ? "DELETE":"PATCH", data })
})
3 Replies
conscious-sapphire
conscious-sapphire4y ago
why should it be true ? can you show a codesandbox reproduction please
fair-rose
fair-roseOP4y ago
if user chooses to delete then state will be changed accordingly. else if the state remains false.
conscious-sapphire
conscious-sapphire4y ago
sorry I can't help with just this info available

Did you find this page helpful?