Skip to content
New issue

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

[useRequest]竞态取消机制与cache #2675

Open
baixiaoyu2997 opened this issue Nov 18, 2024 · 0 comments
Open

[useRequest]竞态取消机制与cache #2675

baixiaoyu2997 opened this issue Nov 18, 2024 · 0 comments

Comments

@baixiaoyu2997
Copy link

baixiaoyu2997 commented Nov 18, 2024

竞态取消并不是真的取消发送请求,那么既然请求已经发送,返回值应该可以被缓存

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时才触发,引用:

但是因为竞态取消机制导致onSuccess只执行一次, 也就是说没办法缓存第一个请求的返回值,这里是否可以改进一下?

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

No branches or pull requests

1 participant