use-http
use-http copied to clipboard
auto managed useFetch does return stale data when body changes
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
to clarify: this usecase is not for mutations, rather for endpoints that need some json data as input, similar to a graphql query
+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}`
.....