# pion [![npm](https://img.shields.io/npm/dt/@pionjs/pion)](https://npm.im/@pionjs/pion) [![npm](https://img.shields.io/npm/v/@pionjs/pion)](https://npm.im/@pionjs/pion) ![coverage](https://api.codelyze.com/v1/projects/badge/clb_880e4a45e784d25b8115b2111d5cf157?r=1) React's Hooks API but for standard web components and [lit-html](https://lit-html.polymer-project.org/) or [hyperHTML](https://codepen.io/WebReflection/pen/pxXrdy?editors=0010). Forked from [haunted](https://github.com/matthewp/haunted). 📚 [Read the Docs](https://pionjs.com) 📖 ```html ``` More example integrations can be found in [this gist](https://gist.github.com/matthewp/92c4daa6588eaef484c6f389d20d5700). ## Hooks pion supports the same API as React Hooks. The hope is that by doing so you can reuse hooks available on npm simply by aliasing package names in your bundler's config. Currently pion supports the following hooks: - [useCallback](https://pionjs.com/hooks/usecallback/) - [useContext](https://pionjs.com/hooks/usecontext/) - [useEffect](https://pionjs.com/hooks/useeffect/) - [useHost](https://pionjs.com/hooks/usehost/) - [useLayoutEffect](https://pionjs.com/hooks/uselayouteffect/) - [useMemo](https://pionjs.com/hooks/usememo/) - [useProperty](https://pionjs.com/hooks/useproperty/) - [useReducer](https://pionjs.com/hooks/usereducer/) - [useRef](https://pionjs.com/hooks/useref/) - [useState](https://pionjs.com/hooks/usestate/) ### Function Signatures ```ts // Or another renderer, see Guides type Renderer = (element: Element) => TemplateResult; interface Options { baseElement: HTMLElement; observedAttributes: string[]; useShadowDOM: boolean; shadowRootInit: ShadowRootInit; styleSheets: (CSSStyleSheet | string)[]; } declare function component( renderer: Renderer, options: Options ): Element; declare function component( renderer: Renderer, baseElement: BaseElement, options: Options ): Element declare function virtual(renderer: Renderer): Directive ``` ## Native properties and ARIA Observed attributes whose name maps to a native reflected property (`aria-*`, `title`, `lang`, `dir`) re-render on change. Read their values in the renderer with `getAttribute` — the attribute holds the verbatim value: ```js customElements.define('my-toggle', component( // aria-expanded=${host.ariaExpanded} — camelCase reads go through the // property, which can coerce; the attribute never does (host) => html`
…
`, { observedAttributes: ['aria-expanded'] }, )); ``` ## License BSD-2-Clause