1.0.4 • Published 4 years ago

hali v1.0.4

Weekly downloads
295
License
MIT
Repository
github
Last release
4 years ago

Hali

hali

Tiny global state management for React ⚛️

npm packagesize treeshaking

Install

npm install hali --save

Usage

import { value, select, effect, useValue } from 'hali';

const countValue = value(1);

effect([countValue], () => console.log(countValue.v));

const doubleCountValue = select([countValue], () => countValue.v * 2);

const plus = () => {
  countValue.v++;
};

const minus = () => {
  countValue.v--;
};

const App = () => {
  const count = useValue(countValue);
  const doubleCount = useValue(doubleCountValue);
  return (
    <div>
      <div>
        <button onClick={plus}>+</button>
        Count: {count}
        <button onClick={minus}>-</button>
      </div>
      Double count: {doubleCount}
    </div>
  );
};

Full example (Counter and Todo)

Demo Source code

Notes

  • If your value is an object (or array), you always return a new object
  const objValue = value({ a: 1, b: 2 });

  // THIS
  objValue.v = { ...objValue.v, c: 3 }

  // NOT THIS (this will work, but will not trigger an update)
  objValue.v.c = 3

Changelog

v1.0.0

Breaking changes:

  • derived has been renamed to select
  • countValue.value has been replaced with countValue.v

Other changes:

  • Improved Typescript support: type is now being inferred from useValue
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago