refactor: 股票数据管理迁移到 Redux,新增类型化 Hooks
- stockSlice: 新增 loadAllStocks action(带缓存检查)
- stockSlice: watchlist 结构升级为 { stock_code, stock_name }[]
- store/hooks.ts: 新增 useAppDispatch, useAppSelector 类型化 hooks
- stockService: 移除 getAllStocks(已迁移到 Redux)
- mock: 股票搜索支持模糊匹配 + 相关性排序
This commit is contained in:
15
src/store/hooks.ts
Normal file
15
src/store/hooks.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Redux Typed Hooks
|
||||
* 提供类型安全的 useDispatch 和 useSelector hooks
|
||||
*/
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import type { TypedUseSelectorHook } from 'react-redux';
|
||||
import { store } from './index';
|
||||
|
||||
// 从 store 推断类型
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
export type AppDispatch = typeof store.dispatch;
|
||||
|
||||
// 类型化的 hooks
|
||||
export const useAppDispatch: () => AppDispatch = useDispatch;
|
||||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|
||||
Reference in New Issue
Block a user