Code React Sweetly
/
React Context
React Context
https://leanpub.com/code-react-sweetly
How React Context Works
https://leanpub.com/code-react-sweetly
How to Create a Context Object
https://leanpub.com/code-react-sweetly
The syntax of the
createContext
API
https://leanpub.com/code-react-sweetly
Example: Create a context object
https://leanpub.com/code-react-sweetly
How to Use the Value of a Context Object
https://leanpub.com/code-react-sweetly
The syntax of the
useContext
Hook
https://leanpub.com/code-react-sweetly
Example: Consume a context object’s value
https://leanpub.com/code-react-sweetly
How to Configure a Parent Component to Provide a Context Value to All Its Descendant Components
https://leanpub.com/code-react-sweetly
The syntax of the context provider
https://leanpub.com/code-react-sweetly
Example: Provide context value to descendant components
https://leanpub.com/code-react-sweetly
How to Override the Context Value Provided to a Child Component
https://leanpub.com/code-react-sweetly
Example: Override a pre-defined context
https://leanpub.com/code-react-sweetly
Example:
useContext
reads only the providers above its calling component
https://leanpub.com/code-react-sweetly
How to Make a Context Object Available to Multiple Files
https://leanpub.com/code-react-sweetly
1. Create a file for your context objects
https://leanpub.com/code-react-sweetly
2. Create and export your context objects
https://leanpub.com/code-react-sweetly
3. Provide context value to a component tree
https://leanpub.com/code-react-sweetly
4. Consume the context value in a descendant component
https://leanpub.com/code-react-sweetly
5. Create the entry script
https://leanpub.com/code-react-sweetly
How to Create a Dynamic Context Value with React State
https://leanpub.com/code-react-sweetly
Essential Things to Know About React Context
https://leanpub.com/code-react-sweetly
1. Prop drilling
https://leanpub.com/code-react-sweetly
2.
children
prop
https://leanpub.com/code-react-sweetly
Up next
Building React Applications with Multi-Page Functionality
In this chapter
React Context
How React Context Works
How to Create a Context Object
How to Use the Value of a Context Object
How to Configure a Parent Component to Provide a Context Value to All Its Descendant Components
How to Override the Context Value Provided to a Child Component
How to Make a Context Object Available to Multiple Files
How to Create a Dynamic Context Value with React State
Essential Things to Know About React Context