From harness-claude
Guides developers on using React Context to share state across the component tree without prop drilling. Covers typed contexts, providers, consumer hooks, and performance considerations.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:react-context-patternThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Share state across the component tree without prop drilling using React Context
Share state across the component tree without prop drilling using React Context
createContext:
interface AuthContextValue {
user: User | null;
signOut: () => void;
}
const AuthContext = createContext<AuthContextValue | null>(null);
export function AuthProvider({ children }: { children: React.ReactNode }) {
const [user, setUser] = useState<User | null>(null);
return (
<AuthContext.Provider value={{ user, signOut: () => setUser(null) }}>
{children}
</AuthContext.Provider>
);
}
export function useAuth(): AuthContextValue {
const ctx = useContext(AuthContext);
if (!ctx) throw new Error('useAuth must be used within AuthProvider');
return ctx;
}
Context provides a mechanism for passing values through the component tree without prop drilling. It is not a replacement for state management — it is a mechanism for making existing state accessible.
Performance: All consumers of a context re-render when the context value changes. Split contexts by update frequency: { theme, toggleTheme } in one context, { user, signOut } in another.
Context vs prop drilling vs state management:
React 19: use(Context) can be called conditionally and inside if blocks, unlike useContext. Equivalent behavior, more flexibility.
https://patterns.dev/react/context-pattern
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeGuides React Context patterns for state management to share state across component trees without prop drilling. Includes TypeScript examples for auth providers.
Manages shared state with React Context and useReducer to avoid prop drilling. Provides split state/dispatch contexts and memoized values for scoped state like auth, theme, or feature flags.
Guides implementation of modern React patterns: hooks, component composition, state management, performance optimizations, concurrent features. Use for building or refactoring components.