Course contentsShow
← React
Lesson 818 of 2,39621. Context FundamentalsFree lesson

Decision Tree: Props, Context, or Library

Follow a practical decision framework for choosing the right state-sharing approach.

Decision Tree: Props, Context, or Library

What you'll learn: A practical framework for deciding when to use props, Context, or an external state library.

The Decision Framework

Choosing the right state-sharing approach isn't arbitrary—there's a logical progression you can follow:

Start Here: Can Props Work?

If data flows through 2-3 components max: Use props. This is the default, most explicit, and easiest-to-debug approach. Don't prematurely optimize by reaching for Context.

If you hit "prop drilling" (4+ levels deep): Move to the next step.

Consider Context

If the data is truly global or feature-scoped: Theme, user authentication, language settings, or feature flags—these belong in Context. They change infrequently and many components need them.

If updates happen frequently (form inputs, animations): Context will cause widespread re-renders. Stick with local state or consider a library.

If only 1-2 components need the data: Create a local Context for that component subtree, not a global one.

Reach for a Library

If you need time-travel debugging or middleware: Redux, Zustand, or similar tools provide developer tools that Context doesn't.

If you have complex async logic: Libraries offer structured patterns for handling side effects and data fetching.

If performance is critical with frequent updates: Libraries like Zustand optimize subscriptions better than Context.

The Analogy

Think of it like mail delivery: props are hand-delivering letters (direct, clear), Context is a building-wide mailroom (shared access point), and libraries are postal services (specialized infrastructure for complex needs).

Key Takeaway: Default to props → upgrade to Context when prop drilling hurts → add a library only when Context's limitations (performance, devtools, patterns) become real problems, not theoretical ones.