Frontend State Management

aj-geddes/useful-ai-prompts/skills/frontend-state-management

作者 aj-geddes3f5182cfd739無授權條款355 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫7 個月前更新

Manage application state using Redux, MobX, Zustand, and Context API. Use when centralizing state for complex applications with multiple components.

AI 產生的概覽

指導前端狀態管理,涵蓋 Redux Toolkit、Zustand、Context API 與 MobX,並提供參考指南和元件範本。

功能
這項技能為前端專案中的應用程式狀態管理實作提供指引。它透過各自的參考指南分別介紹 Redux with Redux Toolkit、Zustand、Context API 搭配 useReducer 以及 MobX,並附上一份元件範本。它也列出撰寫整潔、經過測試且易於維護程式碼的最佳實務。
適用情境
當需要為多個元件共用狀態的複雜應用程式集中管理狀態時使用。它也適合需要可預測的狀態變更、時間旅行偵錯或伺服器狀態同步的情境。
執行需求
不需要指令碼,只有說明與參考文件。在目標技術堆疊中實作時,假定已有 JavaScript 或 TypeScript 前端專案,並安裝了相關的狀態管理函式庫。

Frontend State Management

Table of Contents

Overview

Implement scalable state management solutions using modern patterns and libraries to handle application state, side effects, and data flow across components.

When to Use

  • Complex application state
  • Multiple components sharing state
  • Predictable state mutations
  • Time-travel debugging needs
  • Server state synchronization

Quick Start

Minimal working example:

typescript
// store/userSlice.tsimport { createSlice, createAsyncThunk, PayloadAction } from '@reduxjs/toolkit';
interface User {  id: number;  name: string;  email: string;}
interface UserState {  items: User[];  loading: boolean;  error: string | null;}
const initialState: UserState = {  items: [],  loading: false,  error: null};
export const fetchUsers = createAsyncThunk(  'users/fetchUsers',  async (_, { rejectWithValue }) => {    try {// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Redux with Redux Toolkit (React) [blocked]Redux with Redux Toolkit (React)
Zustand (Lightweight State Management) [blocked]Zustand (Lightweight State Management)
Context API + useReducer [blocked]Context API + useReducer
MobX (Observable State) [blocked]MobX (Observable State)

Best Practices

✅ DO

  • Follow established patterns and conventions
  • Write clean, maintainable code
  • Add appropriate documentation
  • Test thoroughly before deploying

❌ DON'T

  • Skip testing or validation
  • Ignore error handling
  • Hard-code configuration values

來源與署名

來源:aj-geddes/useful-ai-prompts位於skills/frontend-state-management提交3f5182c

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架