hoc-pattern

Creates higher-order components to reuse logic across multiple components.

Updated Apr 28, 2026
One-click install
npx skills add https://github.com/PMKhai/claude-config --skill hoc-pattern-pmkhai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hoc-pattern
Source: https://github.com/PMKhai/claude-config/tree/main/skills/hoc-pattern
Command: npx skills add https://github.com/PMKhai/claude-config --skill hoc-pattern-pmkhai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The Higher-Order Component (HOC) pattern enables reuse of component logic across multiple components, for cross-cutting concerns like authentication, logging, or data fetching.

Core Features & Use Cases

  • Reuse logic across components by wrapping them with higher-order components.
  • Compose with other patterns and hooks to progressively enhance behavior.
  • Understand when to prefer HOCs vs hooks and how to avoid prop-name collisions.

Quick Start

Wrap a component with an HOC to apply shared logic, then export the wrapped component.

Frequently Asked Questions about hoc-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reuse shared React logic across multiple components for cross-cutting concerns?

A higher-order component (HOC) takes a component and returns a new component with enhanced behavior, letting you reuse shared React logic across multiple components for concerns like styling, authorization, and data fetching.

When should I use React hooks instead of higher-order components?

React hooks are often preferred over higher-order components for simpler logic sharing, but HOCs remain valuable for specific cross-cutting concerns, prop merging, and composition ordering where component wrapping is necessary.

How do I avoid prop name collisions when composing multiple higher-order components in React?

When composing multiple higher-order components in React, you avoid prop name collisions through careful prop merging, ensuring wrapped components receive distinct props and controlling composition order to manage overlapping behavior.

What is the best way to handle authorization and data fetching across multiple React components?

The best way to handle authorization and data fetching across multiple React components is applying the HOC pattern to wrap components with shared logic, progressively enhancing behavior through composition.

Does the HOC pattern work with existing React hooks in the same component?

Yes, the higher-order component pattern works with existing React hooks, allowing you to compose HOCs and hooks together to progressively enhance component behavior while choosing the appropriate approach per use case.

Why does my higher-order component override props passed to the wrapped React component?

A higher-order component may override props passed to the wrapped React component if prop merging is not configured correctly, requiring explicit handling of prop-name collisions and composition order to preserve original props.