Guides: Bring your Own Renderer
The main entry point is intended for lit-html users. If you are using lighterhtml or hyperHTML then instead import @pionjs/pion/core
. This export gives you a function that creates Hooks that work with any template library.
import pion, { useState } from '@pionjs/pion/core';
import { html, render } from 'lighterhtml';
const { component } = pion({
render(what, where) {
render(where, () => what);
}
});
function App() {
const [count, setCount] = useState(0);
return html`
<h2>Using lighterhtml!</h2>
<div>Count: ${count}</div>
<button part="button" onclick=${() => setCount(count + 1)}>Increment</button>
`;
}
customElements.define('my-app', component(App));
<html lang="en">
<head>
<script type="module" src="my-app.js"></script>
<style>
body { margin: 0; height: 100vh; }
body, my-app {
display: grid;
place-items: center;
text-align: center;
}
body, my-app {
display: grid;
place-items: center;
text-align: center;
}
my-app {
gap: 20px;
}
my-app::part(count) {
font-size: 24px;
}
my-app::part(button) {
background: transparent;
border: 4px solid black;
padding: 6px 12px;
font-size: 18px;
border-radius: 8px;
}
my-app::part(button):active {
background: rgba(0,0,0,0.1);
transform: translate(1px, 1px);
}
</style>
</head>
<my-app></my-app>
</html>