Skip to content

MatthiasKainer/pure-lit

Folders and files

NameName
Last commit message
Last commit date
Nov 14, 2022
Nov 28, 2023
Nov 28, 2023
Nov 21, 2023
Nov 28, 2023
Aug 28, 2024
May 12, 2021
Jul 4, 2020
Mar 8, 2022
Mar 8, 2022
Jul 4, 2020
Jul 4, 2020
Sep 25, 2024
Sep 25, 2024
Mar 8, 2022
Nov 7, 2023
Sep 10, 2021

Repository files navigation

pure-lit

Version Size vulnerabilities dependencies Statements Branch Functions Lines

lit with pure functions.

Install

npm install pure-lit

or add it to your page as module like this:

<script type="module" src="https://unpkg.com/pure-lit@latest?module"></script>

Getting started

pure-lit.org

The quickest way of getting started is by using JavaScript modules.

Create a file index.html that looks like this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Awesome pure-lit</title>
    <script type="module">
      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: "" },
        }
      );
    </script>
  </head>
  <body>
    <hello-you who="me"></hello-you>
  </body>
</html>

Open it in the browser. Done.

Adding some state

pureLit exports the hooks from lit-element-state-decoupler and lit-element-effect which you can use to manage your state inside the functional components.

You can import them via

import { pureLit, useState, useReducer, useWorkflow, useEffect, useOnce } from "pure-lit";

and then use them like this:

pureLit("hello-world", (element) => {
    const counter = useState(element, 0);
    return html`<button @click="${() => counter.set(counter.get() + 1)}">You clicked me ${counter.get()} times!</button>`
});