WebCell
    Preparing search index...

    Function reaction

    • Method decorator of MobX reaction()

      Type Parameters

      Parameters

      Returns (
          effect: ReactionEffect<V>,
          __namedParameters: ClassMethodDecoratorContext<C>,
      ) => void

      import { observable } from 'mobx';
      import { component, observer, reaction } from 'web-cell';

      @component({ tagName: 'my-tag' })
      @observer
      export class MyTag extends HTMLElement {
      @observable
      accessor count = 0;

      @reaction(({ count }) => count)
      handleCountChange(newValue: number, oldValue: number) {
      console.log(`Count changed from ${oldValue} to ${newValue}`);
      }

      render() {
      return (
      <button onClick={() => this.count++}>
      Up count {this.count}
      </button>
      );
      }
      }