Last active
February 6, 2021 09:09
-
-
Save paigen11/b760039d92168515900cc62e9ba31536 to your computer and use it in GitHub Desktop.
A sample of how to wrap the component providing the context values in a React application.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<CheckoutDrawerContext.Provider value={{ showDrawer, toggleCheckoutDrawer }}> | |
<section className="cart-checkout"> | |
<CartDrawer selectedCartItems={selectedCartItems} /> | |
</section> | |
</CheckoutDrawerContext.Provider> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Had a bit more reading around about the dummy function/values when the context is initialised, and I believe the rationale behind that is that state isn't guaranteed to be initialised, so the
.Consumer
part could/would end up with undefined values and functions.Enjoyed learning context - thanks for the tutorial.