Context API

  • This lesson introduces the React Context API and explains how to share data across the component tree.

  • Context API


    When to Use Context

    Use Context when data is:

    • Global

    • Required by many components

    • Rarely changing

    Examples:

    • Auth user

    • Theme

    • Language

    Context vs Props

    Props

    Context

    Component-to-component

    Global access

    Easy for small apps

    Best for large apps

    Can cause drilling

    No drilling

    Context solves prop drilling.