Skip to content

treeder/state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

state

Super lightweight JavaScript state library using ESM modules. Modern and easy to use.

Features:

  • Uses localStorage so state remains intact even if user leaves and comes back.
  • Can listen for state changes from anywhere, even across browser tabs!

Usage

Import this library:

<script type="module">
import state from 'https://cdn.jsdelivr.net/gh/treeder/state@0/state.js'
</script>

Add listeners:

state.addEventListener('car', (e) => {
    console.log("car change event:", e.detail)
    this.car = e.detail.value
})

Update state elsewhere:

state.set('car', car)

Fetch state on page load:

state.get('car')

Delete from the state:

state.delete('car')

💥 That's it!

You can use this anywhere, including in web components.

About

Lightweight JavaScript client side state package using modules.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published