We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
竞态取消并不是真的取消发送请求,那么既然请求已经发送,返回值应该可以被缓存
const { data, runAsync, loading, error } = useRequest(getBusinessEntityWalletList, { manual: true, cacheKey: '123', staleTime: 15000, onSuccess(data, params) { console.log('==========success', params) }, }) useEffect(() => { setTimeout(() => { const asyncFn = async () => { console.log('=========run') runAsync({ Page: 1, PageSize: 20 }) runAsync({ ...{ Page: 1, PageSize: 20 }, Page: 2, }) } asyncFn() }, 3000) }, [])
setCache的时机在onSuccess和onMutate时才触发,引用:
hooks/packages/hooks/src/useRequest/src/plugins/useCachePlugin.ts
Line 106 in c7bb04c
但是因为竞态取消机制导致onSuccess只执行一次, 也就是说没办法缓存第一个请求的返回值,这里是否可以改进一下?
The text was updated successfully, but these errors were encountered:
这个不好搞,data 只有一份,之前的存哪里呢
Sorry, something went wrong.
在自定义cache的时候是有意义的,因为我可以根据不同的参数来保存数据到localStorage, 这样我在其他组件中如果也触发了相同参数的请求会命中缓存。
这并不算是一个bug, 只是一种建议,或许应该转移到Discussion, 如果你觉得不合理可以随时关闭该issue
可以自己写个单例用map存这数据
No branches or pull requests
竞态取消并不是真的取消发送请求,那么既然请求已经发送,返回值应该可以被缓存
setCache的时机在onSuccess和onMutate时才触发,引用:
hooks/packages/hooks/src/useRequest/src/plugins/useCachePlugin.ts
Line 106 in c7bb04c
但是因为竞态取消机制导致onSuccess只执行一次, 也就是说没办法缓存第一个请求的返回值,这里是否可以改进一下?
The text was updated successfully, but these errors were encountered: