Repository navigation
feat: introduce TanStack Query for push-based data updates - #43
Merged
Merged
Conversation
- Add @tanstack/react-query for smart data fetching - Create useBalanceQuery hook with: - 30s staleTime: tab switching won't trigger re-fetch - 60s polling: automatic balance refresh - Shared cache: multiple components share same data - Request deduplication: concurrent requests are merged - Replace manual useEffect refresh in HomeTab - Add QueryClientProvider to app root This solves the issue where switching tabs would always reload asset information. Now data is cached and only refreshed when stale.
This was referenced Dec 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Tab 切换回首页时,总是会重新加载资产信息,造成不必要的网络请求和用户体验问题。
解决方案
引入 TanStack Query 实现推送式数据服务:
核心改动
安装 @tanstack/react-query
创建
src/lib/query-client.ts- 全局 QueryClient 配置创建
src/queries/use-balance-query.ts- 余额查询 hookstaleTime: Tab 切换不会触发重复请求修改
HomeTab.tsx- 使用新的 query hook 替代手动 useEffect效果
测试