https://github.com/matthiaskainer/pure-lit
Register your lit-elements as a pure functions.
https://github.com/matthiaskainer/pure-lit
html javascript lit lit-html web-component web-components
Last synced: 4 months ago
JSON representation
Register your lit-elements as a pure functions.
- Host: GitHub
- URL: https://github.com/matthiaskainer/pure-lit
- Owner: MatthiasKainer
- License: isc
- Created: 2020-07-04T18:36:12.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-25T15:30:54.000Z (5 months ago)
- Last Synced: 2024-10-15T17:34:33.189Z (4 months ago)
- Topics: html, javascript, lit, lit-html, web-component, web-components
- Language: TypeScript
- Homepage: https://pure-lit.org
- Size: 1.82 MB
- Stars: 25
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Contributing: CONTRIBUTING.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# pure-lit
[](https://www.npmjs.com/package/pure-lit)
[](https://bundlephobia.com/result?p=pure-lit)
[](https://snyk.io/test/github/MatthiasKainer/pure-lit?targetFile=package.json)
[](https://bundlephobia.com/result?p=pure-lit)



> [lit](https://lit.dev/) with pure functions.
## Install
`npm install pure-lit`
or add it to your page as module like this:
``
## Getting started
[](https://pure-lit.org)
The quickest way of getting started is by using JavaScript modules.
Create a file `index.html` that looks like this:
```html
Awesome pure-lit
import { html } from "https://unpkg.com/lit@latest?module";
import { pureLit } from "https://unpkg.com/pure-lit@latest?module";pureLit(
"hello-you",
async ({ who }) => {
return html`<div>Hello ${who}!</div>`;
},
{
defaults: { who: "" },
}
);
```
Open it in the browser. Done.
## Adding some state
pureLit exports the hooks from [lit-element-state-decoupler](https://github.com/MatthiasKainer/lit-element-state-decoupler) and [lit-element-effect](https://github.com/MatthiasKainer/lit-element-effect) which you can use to manage your state inside the functional components.
You can import them via
```typescript
import { pureLit, useState, useReducer, useWorkflow, useEffect, useOnce } from "pure-lit";
```and then use them like this:
```typescript
pureLit("hello-world", (element) => {
const counter = useState(element, 0);
return html` counter.set(counter.get() + 1)}">You clicked me ${counter.get()} times!`
});
```