Lexicon
⌘K
Explore
ExploreGuidesNotes
WriteMy LibraryBooks
Sign in
Browse

Bug Bounty

  • Only Bug Bounty Checklist You'll Ever Need!!!
  • Only Bug Bounty Checklist You'll Ever Need!!! V2

Databases

  • Database indexing basics

DevOps

  • How environment variables work

Git

  • Git commands I use every day

JavaScript

  • JavaScript async and await

Kotlin

  • Kotlin coroutines overview

Linux

  • Useful Linux filesystem commands

Performance

  • How caching improves application performance

React

  • React component design principles

Reference

  • Markdown formatting reference

Software Craft

  • Clean code naming practices
  • Debugging checklist

SQL

  • SQL joins explained

Swift

  • SwiftUI state management

Web

  • API pagination patterns
  • Understanding HTTP status codes
New noteSuggest a guide

Lexicon

a personal knowledge base

React

React component design principles

scorpionxdevUpdated 5/5/2026 · 2 min read · 0 views
PDFHistory

A handful of principles that keep React components easy to change. None of them are rules, but ignoring all of them tends to produce components that are painful to touch six months later.

Keep components small and focused

A component should do one thing. If you struggle to name it, or its render function scrolls off the screen, it is probably two components.

Separate presentation from logic

Push data fetching and business rules up into hooks or container components, and keep leaf components dumb. A dumb component that only takes props is trivial to test and reuse.

function useUser(id: string) {
  const [user, setUser] = useState<User | null>(null);
  useEffect(() => {
    let active = true;
    getUser(id).then((u) => active && setUser(u));
    return () => { active = false; };
  }, [id]);
  return user;
}

function UserCard({ user }: { user: User }) {
  return <div className='card'>{user.name}</div>;
}

Lift state only as high as it needs to go

Shared state belongs at the closest common ancestor, not at the top of the app. Global state for everything makes every change ripple.

Props are a contract

  • Keep the prop list short. Many props is a smell that the component does too much.
  • Prefer specific props over a giant config object.
  • Use children for composition instead of passing render logic through props.

Derive, do not duplicate

If a value can be computed from existing state or props, compute it during render instead of storing it in another piece of state. Duplicated state drifts out of sync.

// Do not store this in state, just derive it
const completed = todos.filter((t) => t.done).length;

Keys must be stable

List keys should be stable identifiers, not array indexes. Index keys cause subtle bugs when the list reorders or items are inserted.

Reading progress0%
scorpionxdev@scorpionxdev

Effects are for synchronizing with the outside world

Reach for useEffect to sync with something external such as the network, a subscription, or the DOM. If you are only transforming data for rendering, you probably do not need an effect at all.

0 comments

Sign in to join the discussion.