How to use the haunted.createContext function in haunted

To help you get started, we’ve selected a few haunted examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geocine / web-components-hooks-demo / src / context / shop-context.js View on Github external
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);

haunted

Hooks for web components

BSD-2-Clause
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis