BACK TO BLOG
COVER IMAGE
My Favorite React Patterns
Development
May 27, 20269 min read

My Favorite React Patterns

A collection of React patterns that help me write components that are easier to understand, maintain, and evolve.

ReactPatternsTypeScript

After years of building React applications, certain patterns keep showing up in the cleanest, most maintainable codebases. These are not tricks or hacks — they are structural approaches that make components easier to reason about, test, and extend.

1. Compound Components

Compound components let you express complex UI relationships through JSX composition, without prop-drilling or clunky configuration objects.

Compound component exampletsx
<Accordion>
  <Accordion.Item value="one">
    <Accordion.Trigger>What is this?</Accordion.Trigger>
    <Accordion.Content>
      A compound component pattern.
    </Accordion.Content>
  </Accordion.Item>
</Accordion>

2. Container / Presentational Split

Separate the logic from the rendering. A container component handles data fetching, state, and side effects. A presentational component renders UI from props and nothing else.

TABLE — Container vs Presentational responsibilities
ResponsibilityContainerPresentational
Fetch dataYesNo
Manage stateYesMinimal
Render UIDelegatesYes
Accept propsFewMany
Easy to testModerateVery easy
ReusableLowHigh
Container vs Presentational responsibilities

3. Custom Hooks for Logic Reuse

Any time I find myself duplicating logic across two components, it goes into a custom hook. Hooks are the cleanest unit of abstraction React has.

useLocalStorage hooktsx
function useLocalStorage<T>(key: string, initialValue: T) {
  const [storedValue, setStoredValue] = useState<T>(() => {
    try {
      const item = window.localStorage.getItem(key);
      return item ? JSON.parse(item) : initialValue;
    } catch {
      return initialValue;
    }
  });

  const setValue = (value: T) => {
    setStoredValue(value);
    window.localStorage.setItem(key, JSON.stringify(value));
  };

  return [storedValue, setValue] as const;
}

Patterns to Use With Care

  • Higher-Order Components (HOCs) — hooks usually do it better
  • Context for all state — Context re-renders are broad
  • Deeply nested compound components — keep trees shallow
  • Over-abstracting early — wait for the pattern to emerge naturally

Write the simplest thing that could possibly work. Reach for patterns only when the code tells you it needs them.

Abdullah Al Maksud
Abdullah Al Maksud

WRITTEN BY

Abdullah Al Maksud

Developer, designer, writer.

/ RELATED

MORE IN DEVELOPMENT

AM

© 2026 Abdullah Al Maksud
All rights reserved.

QUICK LINKS

LET'S CONNECT

Open to interesting projects and opportunities.

SAY HELLO 👋
Designed & Built by Abdullah Al MaksudDhaka, Bangladesh 🇧🇩