1.0.1 • Public • Published


A lightweight state management with localstorage persistance.


#npm i @danielturner/lit-state


After adding lit-state to your application you need to replace LitElement with LitState for ANY view that is going to be using or managing state.


import { css, html } from 'lit-element';
import { LitState } from '../../lit-state/index.js';

export class TestState extends LitState {

Setting state in properties is your next step:

  static get properties() {
    return {
      state: {
        type: Object,

Note: Your properties should have more properties than state

Set the initial value for state in the constructor, don't forget to set the keys you are interested in following for this view.

  constructor() {
    this.state = {
      welcome: '',
      counter: 0,

Note: Your constructor most likely will have more than just state.

One place in your app (possible the app's shell) will control the state. This element is the controller. Place it in your render method.


To initialize a value outside the constructor use the firstUpdated method Calling the notify change triggers a state change across your app.

  firstUpdated() {
    this.notifyChange('welcome', 'Welcome to state');

State changes can be anything, and any time during your apps lifecycle.

  __increment() {
    this.counter += 1;
    this.notifyChange('counter', this.counter);

Or leverage the updated lifecycle.

  updated(changeProperties) {
    changedProperties.forEach((oldValue, propName) => {
      console.log(`${propName} changed. oldValue: ${oldValue}`);
      this.notifyChange(propName, this[propName]);

LitState uses two events stateChanged and stateChangeRequest

It is not recommended to use these to trigger updates.


If you want to use sessionStorage instead of localStorage to limit the persistence to the session. Simply change the controller element in the render method to the following.

  <lit-controller sessionStorage>

Package Sidebar


npm i @danielturner/lit-state

Weekly Downloads






Unpacked Size

14.3 kB

Total Files


Last publish


  • danielturner