
Frontend State Management
- 432 installs
- 305 repo stars
- Updated March 4, 2026
- aj-geddes/useful-ai-prompts
frontend-state-management is a frontend architecture prompt skill that selects and implements global or feature-level state patterns for developers whose UI complexity, shared data, or async flows outgrow local component
About
frontend-state-management is a useful-ai-prompts skill that helps developers choose and implement state management approaches when React, Vue, or similar UIs exceed local useState or component props. The skill evaluates shared data needs, async data flows, and feature boundaries to recommend patterns such as context providers, Zustand stores, Redux slices, or query-cache layers. Developers reach for frontend-state-management when prop drilling, stale shared state, or race conditions appear during feature growth. Output includes concrete implementation guidance—store structure, selector patterns, and async middleware choices—tailored to the project's existing framework stack.
- Local vs global state tradeoffs
- Store setup with common libraries or context
- Async actions, caching, and optimistic updates
- Derived state and selector patterns
- Testing and debugging state transitions
Frontend State Management by the numbers
- 432 all-time installs (skills.sh)
- Ranked #649 of 2,245 Frontend Development skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill frontend-state-managementAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 432 |
|---|---|
| repo stars | ★ 305 |
| Last updated | March 4, 2026 |
| Repository | aj-geddes/useful-ai-prompts ↗ |
How do you choose frontend state management patterns?
Choose and implement global or feature state patterns when UI complexity, shared data, or async flows outgrow local component state.
Who is it for?
Frontend developers scaling a SPA or component library where local state, prop drilling, or uncoordinated async updates are causing bugs.
Skip if: Skip frontend-state-management for server-only backends, static sites with no client interactivity, or projects already fully committed to an established store with no migration need.
When should I use this skill?
User asks how to manage global state, reduce prop drilling, or structure async data flows in a frontend application
What you get
Selected state architecture, store structure, and implementation patterns for shared or async UI data
- state architecture recommendation
- store implementation patterns
Files
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:
// store/userSlice.ts
import { 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:
| Guide | Contents |
|---|---|
| Redux with Redux Toolkit (React) | Redux with Redux Toolkit (React) |
| Zustand (Lightweight State Management) | Zustand (Lightweight State Management) |
| Context API + useReducer | Context API + useReducer |
| MobX (Observable State) | 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
Context API + useReducer
Context API + useReducer
// context/AuthContext.tsx
import React, { createContext, useReducer, useCallback } from 'react';
interface User {
id: number;
name: string;
email: string;
}
interface AuthState {
user: User | null;
loading: boolean;
error: string | null;
isAuthenticated: boolean;
}
type AuthAction =
| { type: 'LOGIN_START' }
| { type: 'LOGIN_SUCCESS'; payload: User }
| { type: 'LOGIN_ERROR'; payload: string }
| { type: 'LOGOUT' };
const initialState: AuthState = {
user: null,
loading: false,
error: null,
isAuthenticated: false
};
function authReducer(state: AuthState, action: AuthAction): AuthState {
switch (action.type) {
case 'LOGIN_START':
return { ...state, loading: true, error: null };
case 'LOGIN_SUCCESS':
return {
...state,
user: action.payload,
loading: false,
isAuthenticated: true
};
case 'LOGIN_ERROR':
return { ...state, error: action.payload, loading: false };
case 'LOGOUT':
return { ...state, user: null, isAuthenticated: false };
default:
return state;
}
}
interface AuthContextType {
state: AuthState;
login: (email: string, password: string) => Promise<void>;
logout: () => void;
}
export const AuthContext = createContext<AuthContextType | undefined>(undefined);
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [state, dispatch] = useReducer(authReducer, initialState);
const login = useCallback(async (email: string, password: string) => {
dispatch({ type: 'LOGIN_START' });
try {
const response = await fetch('/api/login', {
method: 'POST',
body: JSON.stringify({ email, password })
});
if (!response.ok) throw new Error('Login failed');
const user = await response.json();
dispatch({ type: 'LOGIN_SUCCESS', payload: user });
} catch (error) {
dispatch({
type: 'LOGIN_ERROR',
payload: (error as Error).message
});
}
}, []);
const logout = useCallback(() => {
dispatch({ type: 'LOGOUT' });
}, []);
return (
<AuthContext.Provider value={{ state, login, logout }}>
{children}
</AuthContext.Provider>
);
};
export const useAuth = () => {
const context = React.useContext(AuthContext);
if (!context) {
throw new Error('useAuth must be used within AuthProvider');
}
return context;
};MobX (Observable State)
MobX (Observable State)
// store/UserStore.ts
import { makeObservable, observable, action, runInAction } from 'mobx';
interface User {
id: number;
name: string;
email: string;
}
class UserStore {
users: User[] = [];
loading = false;
error: string | null = null;
constructor() {
makeObservable(this, {
users: observable,
loading: observable,
error: observable,
fetchUsers: action,
addUser: action,
removeUser: action,
clearError: action
});
}
async fetchUsers() {
this.loading = true;
this.error = null;
try {
const response = await fetch('/api/users');
if (!response.ok) throw new Error('Failed to fetch');
const data = await response.json();
runInAction(() => {
this.users = data;
this.loading = false;
});
} catch (error) {
runInAction(() => {
this.error = (error as Error).message;
this.loading = false;
});
}
}
addUser(user: User) {
this.users.push(user);
}
removeUser(id: number) {
this.users = this.users.filter(u => u.id !== id);
}
clearError() {
this.error = null;
}
}
export const userStore = new UserStore();
// Usage with React
import { observer } from 'mobx-react-lite';
const UsersList = observer(() => {
const { users, loading, error, fetchUsers } = userStore;
React.useEffect(() => {
fetchUsers();
}, []);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;
return (
<ul>
{users.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
});Redux with Redux Toolkit (React)
Redux with Redux Toolkit (React)
// store/userSlice.ts
import { 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 {
const response = await fetch('/api/users');
if (!response.ok) throw new Error('Failed to fetch');
return await response.json();
} catch (error) {
return rejectWithValue((error as Error).message);
}
}
);
const userSlice = createSlice({
name: 'users',
initialState,
reducers: {
userAdded(state, action: PayloadAction<User>) {
state.items.push(action.payload);
},
userRemoved(state, action: PayloadAction<number>) {
state.items = state.items.filter(u => u.id !== action.payload);
}
},
extraReducers: (builder) => {
builder
.addCase(fetchUsers.pending, (state) => {
state.loading = true;
state.error = null;
})
.addCase(fetchUsers.fulfilled, (state, action) => {
state.loading = false;
state.items = action.payload;
})
.addCase(fetchUsers.rejected, (state, action) => {
state.loading = false;
state.error = action.payload as string;
});
}
});
export const { userAdded, userRemoved } = userSlice.actions;
export default userSlice.reducer;
// store/index.ts
import { configureStore } from '@reduxjs/toolkit';
import userReducer from './userSlice';
export const store = configureStore({
reducer: {
users: userReducer
}
});
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
// Usage in component
import { useDispatch, useSelector } from 'react-redux';
const UsersList: React.FC = () => {
const dispatch = useDispatch<AppDispatch>();
const { items, loading, error } = useSelector(
(state: RootState) => state.users
);
React.useEffect(() => {
dispatch(fetchUsers());
}, [dispatch]);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;
return (
<ul>
{items.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
};Zustand (Lightweight State Management)
Zustand (Lightweight State Management)
// store/useUserStore.ts
import create from 'zustand';
interface User {
id: number;
name: string;
email: string;
}
interface UserStore {
users: User[];
loading: boolean;
error: string | null;
fetchUsers: () => Promise<void>;
addUser: (user: User) => void;
removeUser: (id: number) => void;
clearError: () => void;
}
export const useUserStore = create<UserStore>((set) => ({
users: [],
loading: false,
error: null,
fetchUsers: async () => {
set({ loading: true, error: null });
try {
const response = await fetch('/api/users');
if (!response.ok) throw new Error('Failed to fetch');
const users = await response.json();
set({ users, loading: false });
} catch (error) {
set({ error: (error as Error).message, loading: false });
}
},
addUser: (user) => set((state) => ({
users: [...state.users, user]
})),
removeUser: (id) => set((state) => ({
users: state.users.filter(u => u.id !== id)
})),
clearError: () => set({ error: null })
}));
// Usage in component
const UsersList: React.FC = () => {
const { users, loading, error, fetchUsers } = useUserStore();
React.useEffect(() => {
fetchUsers();
}, [fetchUsers]);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;
return (
<ul>
{users.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
};// Component: [Name]
// TODO: Customize for your framework (React, Vue, Svelte, etc.)
import React from 'react';
interface Props {
// TODO: Define props
}
export function ComponentName({ }: Props) {
// TODO: Add state and effects
return (
<div>
{/* TODO: Add component markup */}
</div>
);
}
Related skills
FAQ
When should frontend-state-management be used?
frontend-state-management applies when UI complexity, shared data across components, or async flows outgrow local component state. The skill recommends global or feature-scoped patterns before prop drilling and stale state create hard-to-debug frontend bugs.
What does frontend-state-management deliver?
frontend-state-management outputs a chosen state architecture—store layout, selector patterns, and async middleware guidance—matched to the project's frontend framework and current complexity level.