npm.io
1.0.2 • Published 2 years ago

dom-state

Licence
MIT
Version
1.0.2
Deps
0
Size
14 kB
Vulns
0
Weekly
0

DOM-state

Simple library for managing state with a data-attributes.

npm install dom-state

How to use

import { useDomState } from 'dom-state';

const [getState, setState] = useDomState(element, 0);

button.addEventListener('click', () => {
  setState(
    (prev) => prev + 1, // or direct value
    (newState) => `counter: ${newState}`,
  );
});

For more details check source code

How to contribute

If you want to add something, or fix a bug create an issue/PR here, I make sure to check it out.

PS

This is fun project, inspired by article, so use in production at your own risk :)

Keywords