usestore-ts
Install
npm i usestore-ts "experimentalDecorators": true,
"emitDecoratorMetadata": true,Usage
CounterStore
import { singleton } from 'tsyringe';
import { Store, Action } from 'usestore-ts';
/*
* ์ฑ๊ธํค ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์คํ ์ด ๋ฐ์ฝ๋ ์ดํฐ ๋ณด๋ค ์์์ ๋์.
* ์ฑ๊ธํค์ ๋จน์ ํด๋์ค๋ฅผ ์คํ ์ด ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ์ด์๊ฐ ์์ ์ ์์
*/
@singleton()
@Store()
export default class CounterStore {
counter = 0;
// ์ก์
๋ฐ์ฝ๋ ์ดํฐ๋ publish ๋ฉ์๋๋ฅผ ๋จธ๊ธ๊ณ ์๋ค.
@Action()
increase(step = 1) {
this.counter += step;
}
@Action()
decrease(step = 1) {
this.counter -= step;
}
}useCounterStore
CounterController.tsx
Counter.tsx
Last updated