Skip to content

refactor(frontend): 将 useToast Hook 从组件文件中拆出 #31

Description

@mudongliang

背景

frontend/src/components/Toast.jsx 同时导出 React 组件和自定义 Hook useToast。当前 ESLint 因此报告:

Fast refresh only works when a file only exports components
react-refresh/only-export-components

相关文件

  • frontend/src/components/Toast.jsx
  • frontend/src/components/Dashboard.jsx
  • 可新增 frontend/src/hooks/useToast.js

实现范围

  • 将 useToast 移到独立 Hook 模块
  • 更新调用方的导入路径
  • 保留 Toast 组件和 ToastContainer 的现有职责
  • 不改变 Toast 的视觉样式或交互文案

验收标准

  • useToast 位于独立 Hook 文件
  • Toast.jsx 只导出 React 组件
  • Dashboard 使用新的 Hook 导入路径
  • 成功、错误、信息和警告 Toast 仍可正常显示
  • 自动消失和手动关闭行为保持不变
  • 针对修改文件执行 ESLint 时不再出现 react-refresh/only-export-components
  • npm run build 通过

难度与提示

这是一个小型模块拆分任务,适合熟悉 React import/export 和自定义 Hook。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions