hoc-pattern

Create higher-order components that inject shared behavior into React components.

1|Updated Jul 12, 2025
One-click install
npx skills add https://github.com/ubay1/next15-starter --skill hoc-pattern-ubay1
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hoc-pattern
Source: https://github.com/ubay1/next15-starter/tree/main/.agents/skills/hoc-pattern
Command: npx skills add https://github.com/ubay1/next15-starter --skill hoc-pattern-ubay1

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you reuse shared component behavior (like loading states, auth checks, or styling) without duplicating the same logic across many components.

Core Features & Use Cases

  • Logic reuse across components: Wrap multiple components with a single function that injects enhanced behavior consistently.
  • Prop-driven composition: Pass URLs, flags, or other inputs into the HOC so the wrapped component receives only what it needs.
  • Composability guidance: Understand how stacking HOCs works and why wrapper order can change the resulting props and rendering behavior.
  • When to choose HOCs vs hooks: Use HOCs for uncustomized behavior shared widely, and prefer hooks when customization or clarity matters more than shared wrapping.

Quick Start

Ask the AI to show you how to create a higher-order component that fetches data and renders a loading fallback until the wrapped component receives the loaded props.

Frequently Asked Questions about hoc-pattern

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

FAQPage Schema
How do I reuse loading state logic across multiple React components?

You can reuse loading state logic in React by wrapping components in a higher-order component that manages state and injects enhanced behavior, ensuring consistent cross-cutting concerns without duplicating code.

What is the best way to share cross-cutting logic like auth gating in TSX components?

Sharing cross-cutting logic like auth gating in TSX components is best achieved with a higher-order component that takes a component, manages the auth state, and passes the required props through to the wrapped component.

When should I use higher-order components vs hooks for logic reuse in React?

Use higher-order components for uncustomized behavior shared widely across React components, and prefer hooks when customization or clarity matters more than shared wrapping.

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

To avoid prop-name collisions when composing HOCs, ensure the wrapper function manages state and passes props through carefully, as stacking order can change the resulting props and rendering behavior.

Can I pass dynamic parameters like URLs into a higher-order component in React?

Yes, you can pass dynamic parameters like URLs into a higher-order component by accepting additional parameters in the wrapper function, allowing the wrapped component to receive only the props it needs.

Why does the order of stacked higher-order components change rendering behavior?

The order of stacked higher-order components changes rendering behavior because each wrapper modifies the props passed to the next, meaning the sequence of HOC composition directly affects the final props received.