hoc-pattern

Wrap React components with Higher-Order Components to inject shared behavior.

235|25|Updated Mar 24, 2026
One-click install
npx skills add https://github.com/PatternsDev/skills --skill hoc-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hoc-pattern
Source: https://github.com/PatternsDev/skills/tree/main/react/hoc-pattern
Command: npx skills add https://github.com/PatternsDev/skills --skill hoc-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Higher-Order Components (HOCs) provide a reusable way to inject shared behavior into multiple components, reducing duplication and increasing consistency across UI code.

Core Features & Use Cases

  • Reuse and compose component logic across many components without duplicating code.
  • Enable cross-cutting concerns (authentication, logging, data fetching) by wrapping components with a single pattern.
  • Use when you want to extend or modify a component's behavior without changing its internal implementation.

Quick Start

Wrap a component with your HOC to inject shared logic like authentication or data fetching.

Frequently Asked Questions about hoc-pattern

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

FAQPage Schema
How do I reuse component logic like authentication or data fetching across multiple React components?

To reuse component logic across React components, wrap them with a Higher-Order Component (HOC) to inject shared behavior without duplicating code or modifying internal implementations. This pattern reduces duplication and increases consistency across UI code.

What is a Higher-Order Component in React and when should I use it?

A Higher-Order Component (HOC) is a pattern that takes a component and returns a new component to inject shared cross-cutting concerns like logging or authentication. Use it when you need to extend or modify component behavior without changing its internal implementation.

Can I use the HOC pattern to add cross-cutting concerns like logging without changing my component's code?

Yes, you can use the HOC pattern to add cross-cutting concerns like logging by wrapping your existing React component. This enables you to inject shared behavior externally, leaving the internal component implementation completely unchanged.

What is the best way to share cross-cutting UI logic in a React codebase?

The best way to share cross-cutting UI logic in a React codebase is composing components with a Higher-Order Component. This design pattern wraps components to inject reusable behavior, reducing code duplication and increasing consistency across the UI.

When should I not use Higher-Order Components for component reuse?

You should not use Higher-Order Components if you need to modify the internal implementation of a specific component rather than injecting external shared behavior. HOCs are strictly designed for wrapping components to apply reusable cross-cutting concerns like authentication.