0.1.0 • Published 1 year ago

lrhs v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

light react hook store

react light weight data share store, with strict type.

Usage

// /src/store/somestore.ts
import store from 'lrhs';
const { useStore } = store({
  a: 10,
  b: 'hello',
});
export { useStore };

// /src/app/pages/somecomponent.tsx
import { useStore } from '@/store/somestore.ts';
const [a, setA] = useStore('a'); //
setA('ok'); // bad. compile error, type of a must be number
setA(10); // ok
setA((oldValue) => oldValue + 1); // can be set function
const [c] = useStore('c'); // bad. compile error, somestore has no propery named c

// another example
import { createStore } from 'lrhs';
const globalStore = createStore({
  a: 10,
  b: 'hello',
});

globalStore.get('a'); // get property value
globalStore.set('a', 20);
globalStore.set('b', (oldValue) => `${oldValue}.new`);
globalStore.getStore(); // get whole store data object

const [a, setA] = globalStore.useStore('a');
console.log(a);
setA(30);

// hook on updated
globalStore.hook('a', (newValue) => {
  localStorage.setItem('SOME_KEY', JSON.stringify(newValue));
});
0.1.0

1 year ago

0.0.3

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.2

2 years ago

0.0.1

2 years ago