Skip to content

Instantly share code, notes, and snippets.

@paigen11
Last active February 6, 2021 09:09
Show Gist options
  • Save paigen11/b760039d92168515900cc62e9ba31536 to your computer and use it in GitHub Desktop.
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.
<CheckoutDrawerContext.Provider value={{ showDrawer, toggleCheckoutDrawer }}>
<section className="cart-checkout">
<CartDrawer selectedCartItems={selectedCartItems} />
</section>
</CheckoutDrawerContext.Provider>
@readikus
Copy link

readikus commented Feb 6, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment