Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { useContext, component, createContext } from "haunted";
// https://github.com/matthewp/haunted/issues/75
const createConsumer = Context =>
component(
function({ render }) {
const context = useContext(Context);
return render(context);
},
HTMLElement,
{ useShadowDOM: false }
);
const ShopContext = createContext({
products: [],
cart: [],
addProductToCart: () => {},
removeProductFromCart: () => {}
});
ShopContext.Consumer = createConsumer(ShopContext);
customElements.define("shop-provider", ShopContext.Provider);
customElements.define("shop-consumer", ShopContext.Consumer);