From harness-claude
Implements React Context pattern to share infrequent state like themes, users, or flags across component trees without prop drilling. Includes typed providers, safe hooks, and performance tips.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Share state across the component tree without prop drilling using React Context
Implements React Provider Pattern with Context API to share data like theme, locale, or user across component trees without prop drilling. Use when multiple nested components need same data or prop drilling burdens maintenance.
Guides React Context patterns for state management to share state across component trees without prop drilling. Includes TypeScript examples for auth providers.
Implements React component patterns: compound components with context, render props, HOCs, custom hooks, provider with reducer, controlled/uncontrolled, prop getters, state reducer.
Share bugs, ideas, or general feedback.
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