## 主要改动 ### 新增 - 创建 `store/slices/authModalSlice.js` - Redux Slice 管理认证弹窗状态 - 创建 `hooks/useAuthModal.js` - 自定义 Hook,组合 Redux 状态和业务逻辑 ### 修改 - 更新 `store/index.js` - 添加 authModal reducer - 更新 `App.js` - 移除 AuthModalProvider 包裹层 - 更新 5 个组件的 import 路径: - AuthFormContent.js - AuthModalManager.js - WechatRegister.js - HomeNavbar.js - ProtectedRoute.js ### 删除 - 删除 `contexts/AuthModalContext.js` - 旧的 Context 实现 ## 迁移效果 - ✅ 减少 Provider 嵌套层级(4层 → 3层) - ✅ 统一状态管理架构(Redux) - ✅ 更好的调试体验(Redux DevTools) - ✅ 保持 API 兼容性(无破坏性修改) ## 技术细节 - 使用 `useRef` 存储 `onSuccessCallback`(函数不可序列化) - 保持与 AuthContext 的依赖关系(AuthProvider 暂未迁移) - 所有业务逻辑保持不变,仅改变状态管理方式 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
// src/store/index.js
|
|
import { configureStore } from '@reduxjs/toolkit';
|
|
import communityDataReducer from './slices/communityDataSlice';
|
|
import posthogReducer from './slices/posthogSlice';
|
|
import industryReducer from './slices/industrySlice';
|
|
import stockReducer from './slices/stockSlice';
|
|
import authModalReducer from './slices/authModalSlice';
|
|
import posthogMiddleware from './middleware/posthogMiddleware';
|
|
|
|
export const store = configureStore({
|
|
reducer: {
|
|
communityData: communityDataReducer,
|
|
posthog: posthogReducer, // ✅ PostHog Redux 状态管理
|
|
industry: industryReducer, // ✅ 行业分类数据管理
|
|
stock: stockReducer, // ✅ 股票和事件数据管理
|
|
authModal: authModalReducer, // ✅ 认证弹窗状态管理
|
|
},
|
|
middleware: (getDefaultMiddleware) =>
|
|
getDefaultMiddleware({
|
|
serializableCheck: {
|
|
// 忽略这些 action types 的序列化检查
|
|
ignoredActions: [
|
|
'communityData/fetchPopularKeywords/fulfilled',
|
|
'communityData/fetchHotEvents/fulfilled',
|
|
'posthog/trackEvent/fulfilled', // ✅ PostHog 事件追踪
|
|
'stock/fetchEventStocks/fulfilled',
|
|
'stock/fetchStockQuotes/fulfilled',
|
|
],
|
|
},
|
|
}).concat(posthogMiddleware), // ✅ PostHog 自动追踪中间件
|
|
});
|
|
|
|
export default store;
|