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