Get started with mobx CDN

MIT licensed

MobX: library for observable, reactive state management.

Tags:
  • mobx
  • mobservable
  • observable
  • react-component
  • react
  • reactjs
  • reactive
  • model
  • frp
  • functional-reactive-programming
  • state management
  • data flow

Stable version

Copied!

How to start using mobx CDN


// Import MobX and its reaction decorator
import { observable, action, computed, reaction } from 'https://cdn.cdnhub.io/mobx/6.12.0/mobx.umd.production.min.js';

// Define an observable store
class CounterStore {
  // Make 'count' observable
  @observable count = 0;

  // Define an action to increment the count
  @action increment() {
    this.count++;
  }

  // Define a computed property to double the count
  @computed get doubledCount() {
    return this.count * 2;
  }

  // Define a reaction to log the doubled count when it changes
  @reaction(() => this.doubledCount)
  logDoubledCount() {
    console.log('Doubled count:', this.doubledCount);
  }
}

// Create an instance of the store and subscribe to updates
const store = new CounterStore();
store.subscribe(() => {
  console.log('Count changed:', store.count);
});

// Increment the count and observe the reactions
store.increment();
store.increment();
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions

2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.0-beta.1 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.4.0 2.4.0-alpha1 2.4.0-beta1 2.4.0-fix427 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.0-alpha1 2.5.0-rc1 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.0-beta 3.0.0 3.0.0-rc.1 3.0.0-rc.2 3.0.1 3.0.2 3.1.0 3.1.1 3.1.10 3.1.11 3.1.11-rollup 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.3.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