- 使用 useGlobalErrorHandler Hook 替代内联错误处理 - 使用 AppProviders 替代 6 层 Provider 嵌套 - 使用 GlobalComponents 替代分散的全局组件 - 简化 AppContent,只保留 PostHog 初始化和路由渲染 效果: - App.js 从 165 行减少到 62 行 (-62%) - 总计从原始 330 行减少到 62 行 (-81%) - 代码结构清晰,职责分明 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
63 lines
1.6 KiB
JavaScript
Executable File
63 lines
1.6 KiB
JavaScript
Executable File
/**
|
|
=========================================================
|
|
Vision UI PRO React - v1.0.0
|
|
=========================================================
|
|
Product Page: https://www.creative-tim.com/product/vision-ui-dashboard-pro-react
|
|
Copyright 2021 Creative Tim (https://www.creative-tim.com/)
|
|
Design and Coded by Simmmple & Creative Tim
|
|
=========================================================
|
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Visionware.
|
|
*/
|
|
|
|
import React, { useEffect } from "react";
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
// Routes
|
|
import AppRoutes from './routes';
|
|
|
|
// Providers
|
|
import AppProviders from './providers/AppProviders';
|
|
|
|
// Components
|
|
import GlobalComponents from './components/GlobalComponents';
|
|
|
|
// Hooks
|
|
import { useGlobalErrorHandler } from './hooks/useGlobalErrorHandler';
|
|
|
|
// Redux
|
|
import { initializePostHog } from './store/slices/posthogSlice';
|
|
|
|
// Utils
|
|
import { logger } from './utils/logger';
|
|
|
|
/**
|
|
* AppContent - 应用核心内容
|
|
* 负责 PostHog 初始化和渲染路由
|
|
*/
|
|
function AppContent() {
|
|
const dispatch = useDispatch();
|
|
|
|
// 🎯 PostHog Redux 初始化
|
|
useEffect(() => {
|
|
dispatch(initializePostHog());
|
|
logger.info('App', 'PostHog Redux 初始化已触发');
|
|
}, [dispatch]);
|
|
|
|
return <AppRoutes />;
|
|
}
|
|
|
|
/**
|
|
* App - 应用根组件
|
|
* 设置全局错误处理,提供 Provider 和全局组件
|
|
*/
|
|
export default function App() {
|
|
// 全局错误处理
|
|
useGlobalErrorHandler();
|
|
|
|
return (
|
|
<AppProviders>
|
|
<AppContent />
|
|
<GlobalComponents />
|
|
</AppProviders>
|
|
);
|
|
} |