hoc-pattern

Wrap React components with Higher-Order Components to reuse cross-cutting logic.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/thinkeloquent/mta-ui-atomicdesign-organisms --skill hoc-pattern-thinkeloquent
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hoc-pattern
Source: https://github.com/thinkeloquent/mta-ui-atomicdesign-organisms/tree/main/.agents/skills/hoc-pattern
Command: npx skills add https://github.com/thinkeloquent/mta-ui-atomicdesign-organisms --skill hoc-pattern-thinkeloquent

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Reusable logic across multiple components is often duplicated via similar patterns for concerns like authentication, logging, or data fetching. The HOC pattern enables sharing that logic by wrapping components, reducing code duplication and improving consistency.

Core Features & Use Cases

  • Reusable cross-cutting logic: Extract common behavior into Higher-Order Components that can be applied to many components.
  • Clear composition: HOCs can be layered or composed, with attention to prop naming to avoid collisions.
  • Guidance on when to use Hooks: For many scenarios, Hooks offer lighter-weight alternatives, and this section discusses trade-offs.

Quick Start

Wrap your component with a Higher-Order Component to reuse cross-cutting logic across multiple components.

Frequently Asked Questions about hoc-pattern

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

FAQPage Schema
How do I reuse React component logic for authentication and logging across multiple files?

You can reuse cross-cutting React logic by wrapping components with Higher-Order Components. An HOC takes a component and returns an enhanced version that adds shared behavior while maintaining prop compatibility, reducing code duplication for concerns like authentication and logging.

What is a Higher-Order Component in React and how does it work?

A Higher-Order Component is a pattern that takes a React component and returns a new enhanced component. It consolidates cross-cutting logic like data fetching by wrapping the original component, allowing you to share behavior across multiple components without duplicating code.

How do I compose multiple Higher-Order Components without prop collisions in React?

You can compose multiple Higher-Order Components by layering them to apply different cross-cutting concerns sequentially. The pattern requires careful attention to prop naming to avoid collisions and ensure the wrapped components maintain their expected prop compatibility.

When should I use React Hooks instead of Higher-Order Components for code reuse?

You should use React Hooks instead of Higher-Order Components when you need a lighter-weight alternative for sharing logic. The HOC pattern discusses these trade-offs, guiding when Hooks offer a simpler solution versus when the structured HOC wrapping approach is more appropriate.

Does the Higher-Order Component pattern require any external dependencies to work in JavaScript?

No, the Higher-Order Component pattern relies solely on JavaScript and React functionality without requiring external dependencies. It uses a structured approach where a function takes a component and returns an enhanced version to promote code reuse natively.