`setTaskSummary` 在 useEffect 里被使用(约 259 行),但它的 useState 声明在 约 420 行 —— eslint `react-hooks/immutability` 判为「访问了尚未声明的变量」。 这是 main 上就存在的历史问题,会让 `npm run lint` 失败。 **运行时其实不会踩 TDZ**(useEffect 在渲染后执行、且内部是 async,等到真正调用 setter 时声明早已执行完),但**声明与使用相隔 160 行**本身就是隐患:任何一次 把调用改成同步、或把 effect 往上移的重构都会真的炸。 处理:把 useState 声明移到任务相关 state 区块(taskPage / taskStatus / taskTotal 旁边)—— 既满足规则,也让这组状态聚在一起。先确认过**组件在声明之前没有任何 早期 return**,所以上移不会改变 hooks 的调用顺序。 验证: - `npx eslint src/pages/LoginTasksPage.tsx` → 0 errors(原本 1 error) - `npm run lint` → **exit 0**(29 个 warning 是既有的 react-refresh 提示,未动) - `npm run build`(tsc -b && vite build)通过
React + TypeScript + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- @vitejs/plugin-react uses Oxc
- @vitejs/plugin-react-swc uses SWC
React Compiler
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see this documentation.
Expanding the ESLint configuration
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
// Other configs...
// Remove tseslint.configs.recommended and replace with this
tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
tseslint.configs.stylisticTypeChecked,
// Other configs...
],
languageOptions: {
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
])
You can also install eslint-plugin-react-x and eslint-plugin-react-dom for React-specific lint rules:
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
// Other configs...
// Enable lint rules for React
reactX.configs['recommended-typescript'],
// Enable lint rules for React DOM
reactDom.configs.recommended,
],
languageOptions: {
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
])