feat: 创建 AppProviders 统一管理 Provider 层级
- 创建 src/providers/AppProviders.js (64行) - 集中管理 6 层 Provider: Redux, Chakra, ErrorBoundary, Notification, Auth, AuthModal - 添加详细的 JSDoc 注释说明 Provider 层级顺序 优势: - Provider 配置独立管理,易于维护 - 避免 App.js 中 6 层嵌套 - 便于测试和重用 - 新增 Provider 只需修改一个文件 Provider 层级 (从外到内): 1. ReduxProvider - 状态管理层 2. ChakraProvider - UI 框架层 3. ErrorBoundary - 错误边界 4. NotificationProvider - 通知系统 5. AuthProvider - 认证系统 6. AuthModalProvider - 认证弹窗管理 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
64
src/providers/AppProviders.js
Normal file
64
src/providers/AppProviders.js
Normal file
@@ -0,0 +1,64 @@
|
||||
// src/providers/AppProviders.js
|
||||
// 集中管理应用的所有 Provider
|
||||
|
||||
import React from 'react';
|
||||
import { ChakraProvider } from '@chakra-ui/react';
|
||||
import { Provider as ReduxProvider } from 'react-redux';
|
||||
|
||||
// Redux Store
|
||||
import { store } from '../store';
|
||||
|
||||
// Theme
|
||||
import theme from '../theme/theme.js';
|
||||
|
||||
// Contexts
|
||||
import { AuthProvider } from '../contexts/AuthContext';
|
||||
import { AuthModalProvider } from '../contexts/AuthModalContext';
|
||||
import { NotificationProvider } from '../contexts/NotificationContext';
|
||||
|
||||
// Components
|
||||
import ErrorBoundary from '../components/ErrorBoundary';
|
||||
|
||||
/**
|
||||
* AppProviders - 应用的 Provider 容器
|
||||
* 集中管理所有 Context Provider,避免 App.js 中层级嵌套过深
|
||||
*
|
||||
* Provider 层级顺序 (从外到内):
|
||||
* 1. ReduxProvider - 状态管理层
|
||||
* 2. ChakraProvider - UI 框架层
|
||||
* 3. ErrorBoundary - 错误边界
|
||||
* 4. NotificationProvider - 通知系统
|
||||
* 5. AuthProvider - 认证系统
|
||||
* 6. AuthModalProvider - 认证弹窗管理
|
||||
*
|
||||
* @param {Object} props
|
||||
* @param {React.ReactNode} props.children - 子组件
|
||||
*/
|
||||
export function AppProviders({ children }) {
|
||||
return (
|
||||
<ReduxProvider store={store}>
|
||||
<ChakraProvider
|
||||
theme={theme}
|
||||
toastOptions={{
|
||||
defaultOptions: {
|
||||
position: 'top',
|
||||
duration: 3000,
|
||||
isClosable: true,
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ErrorBoundary>
|
||||
<NotificationProvider>
|
||||
<AuthProvider>
|
||||
<AuthModalProvider>
|
||||
{children}
|
||||
</AuthModalProvider>
|
||||
</AuthProvider>
|
||||
</NotificationProvider>
|
||||
</ErrorBoundary>
|
||||
</ChakraProvider>
|
||||
</ReduxProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default AppProviders;
|
||||
Reference in New Issue
Block a user