0.0.4 • Published 2 months ago

@dgaa/use-store-subscribe v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

use-store-subscribe

Building

Run nx build use-store-subscribe to build the library.

Running unit tests

Run nx test use-store-subscribe to execute the unit tests via Jest.

Usage

// store.ts

class SomeStore {
  public storeSubject = new StoreSubject(1);

  public updateValue(value: number) {
    this.storeSubject.next(value);
  }
}

export const someStore = new SomeStore();
// Component.tsx

import { useStoreSubscribe } from '@dgaa/use-store-subscribe';
import { someStore } from './store';

const Component = () => {
  const currentValue = useStoreSubscribe(someStore.storeSubject);

  const updateValue = () => {
    someStore.updateValue(currentValue + 1);
  };

  return (
    <div>
      {currentValue}
      <button onClick={updateValue}>Update</button>
    </div>
  );
};
0.0.4

2 months ago

0.0.1

11 months ago