Joel Watson

Joel.Watson92@gmail.com | LinkedIn: /in/joel3rbear | Twitter: @Joel3rBear


Project maintained by JoelMWatson Hosted on GitHub Pages — Theme by mattgraham

Home » Reading Notes » React Context API


Class 28 Reading: Context API

What is the difference between the variables MyContext and MyProvider in the examples above?

The difference between the MyContext variable and the MyProvider variable from the example is that the MyContext variable is just a reference to a new react context that was created. The MyProvider variable is an actual component that uses the context to defined/modified state variables.

Why is context useful?

Context is useful because it allows us to pass state variables directly to the component that needs them without having to pass it to each component as a prop.

Can a component outside of a provider get its context?

Components outside the provider will not have access to the same context that is accessible inside the provider.