Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

auto managed useFetch does return stale data when body changes #298

Open
macrozone opened this issue Oct 23, 2020 · 2 comments
Open

auto managed useFetch does return stale data when body changes #298

macrozone opened this issue Oct 23, 2020 · 2 comments

Comments

@macrozone
Copy link

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
Copy link
Author

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

@AntonShch
Copy link

AntonShch commented Jul 13, 2021

+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}`
.....

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants