use-http icon indicating copy to clipboard operation
use-http copied to clipboard

auto managed useFetch does return stale data when body changes

Open macrozone opened this issue 5 years ago • 2 comments

Describe the bug

useFetch sends old post body data, even if you specify a dependency array

⚠️ Make a Codesandbox ⚠️

https://codesandbox.io/s/usefetch-provider-requestresponse-interceptors-forked-39tn3?file=/src/index.js

it uses an echo server

To Reproduce

see code sandbox

Expected behavior

useFetch should resend the post request when the dependency array changes

macrozone avatar Oct 23 '20 10:10 macrozone

to clarify: this usecase is not for mutations, rather for endpoints that need some json data as input, similar to a graphql query

macrozone avatar Oct 23 '20 10:10 macrozone

+1, i using apollo graphql in most projects, but in current needed REST API, after research in google/stackoverflow - use-http turned out to the best solution a like similar to apollo, but i faced with same problem as in thread.

For resolve this problem had to do so bad =(


  useDeepCompareEffect(() => {
    setRequestNumber((prev) => prev + 1);
  }, [initialOptions]);

 const { data, ...fetchResult } = useFetch(
    `${API.users.getUsers}?r?=${requestNumber}`
.....

AntonShch avatar Jul 13 '21 00:07 AntonShch