6.12.3 • Published 22 days ago

mobx v6.12.3

Weekly downloads
633,421
License
MIT
Repository
github
Last release
22 days ago

MobX

Simple, scalable state management.

npm version OpenCollective OpenCollective Discuss on Github Coverage Status View changelog


Documentation

Documentation can be found at mobx.js.org.


Sponsors

MobX is made possible by the generosity of the sponsors below, and many other individual backers. Sponsoring directly impacts the longevity of this project.

🥇 Gold sponsors (\$2500+ total contribution):

🥈 Silver sponsors (\$500+ total contributions):

Introduction

Anything that can be derived from the application state, should be. Automatically.

MobX is a signal based, battle-tested library that makes state management simple and scalable by transparently applying functional reactive programming. The philosophy behind MobX is simple:


A quick example

So what does code that uses MobX look like?

import React from "react"
import ReactDOM from "react-dom"
import { makeAutoObservable } from "mobx"
import { observer } from "mobx-react-lite"

// Model the application state.
function createTimer() {
    return makeAutoObservable({
        secondsPassed: 0,
        increase() {
            this.secondsPassed += 1
        },
        reset() {
            this.secondsPassed = 0
        }
    })
}

const myTimer = createTimer()

// Build a "user interface" that uses the observable state.
const TimerView = observer(({ timer }) => (
    <button onClick={() => timer.reset()}>Seconds passed: {timer.secondsPassed}</button>
))

ReactDOM.render(<TimerView timer={myTimer} />, document.body)

// Update the 'Seconds passed: X' text every second.
setInterval(() => {
    myTimer.increase()
}, 1000)

The observer wrapper around the TimerView React component will automatically detect that rendering depends on the timer.secondsPassed observable, even though this relationship is not explicitly defined. The reactivity system will take care of re-rendering the component when precisely that field is updated in the future.

Every event (onClick / setInterval) invokes an action (myTimer.increase / myTimer.reset) that updates observable state (myTimer.secondsPassed). Changes in the observable state are propagated precisely to all computations and side effects (TimerView) that depend on the changes being made.

This conceptual picture can be applied to the above example, or any other application using MobX.

Getting started

To learn about the core concepts of MobX using a larger example, check out The gist of MobX page, or take the 10 minute interactive introduction to MobX and React. The philosophy and benefits of the mental model provided by MobX are also described in great detail in the blog posts UI as an afterthought and How to decouple state and UI (a.k.a. you don’t need componentWillMount).

Further resources

The MobX book

The MobX Quick Start Guide ($24.99) by Pavan Podila and Michel Weststrate is available as an ebook, paperback, and on the O'Reilly platform (see preview).

Videos

Credits

MobX is inspired by reactive programming principles, which are for example used in spreadsheets. It is inspired by model–view–viewmodel frameworks like MeteorJS's Tracker, Knockout and Vue.js, but MobX brings transparent functional reactive programming (TFRP, a concept which is further explained in the MobX book) to the next level and provides a standalone implementation. It implements TFRP in a glitch-free, synchronous, predictable and efficient manner.

A ton of credit goes to Mendix, for providing the flexibility and support to maintain MobX and the chance to prove the philosophy of MobX in a real, complex, performance critical applications.

@xh/hoist42-pro-markdown-nice@jsmodules/models@vectis/corejs@stoplight/cliboard-sdkdeepstream.io-mobx@patternfly/react-topology@ablestack/rdg-apollo-mobx-connector@yelloan/redoc-clireact-use-mahorc-with-nextjsreact-pathway-mapper@plarin/vendor@plarintest/vendor@darkhm/essence-constructor-dllhadith-appvsnodetmp-ng9-angular-tree-componentwebshop-frontenddsm-shared-componentsmegatron-front@deriv/bot-web-ui@deriv/traderscenic-clientgrader-displayholly-react-scripts@dance-show/react-showlcyhy-react-componentocr-frontcyberforce-essentials@agora/react-cabinet@umg-mira/builder-editor-pluginwq-mobilemsi.cubo.portalwuqin_mobilecfp-app-skapacfp-app-testcfa-test1-skapaevaformilottie@dewen_li/gatsby-theme-bodiless@dewen_li/components@dewen_li/core@dewen_li/richtext@ssskram/auth-clientkhodroinja-ui-corefunmituioffice-ui-fabric-react-extensionsgoldmine-clientcfpppiral-compass-baselegal-content-front-webweb-pdm-doc@peerio/peerio-icebearpiral-compass-ace-editorpiral-compass-animatepiral-compass-apipiral-compass-badgepiral-compass-buttonpiral-compass-chartpiral-compass-checkboxpiral-compass-collapsepiral-compass-confirm-dialogpiral-compass-draggablepiral-compass-iconpiral-compass-inputpiral-compass-line-progresspiral-compass-radiopiral-compass-resource-metricspiral-compass-selectpiral-compass-spinnerpiral-compass-status-brickpiral-compass-stepperpiral-compass-themespiral-compass-tooltipdarth-orga-uidarth-privilege-ui@logicflow/lf-core@lemopo/mail-editorpg-taskq-dashboard@cloudsense/cs-redoc-cli@webull/mail-editortechsee-app-template@psimk/porter-react-skeletonleads-capture-extensionhlj-scriptshlj-scripts-testthilenius-web-corevanilli-shopfw-way-findingcontent-client@ldlework/react-ecs-3@ldlework/react-ecs2@dariosechi/badge@dariosechi/button@dariosechi/credit-card@dariosechi/feather@dariosechi/forms@dariosechi/header
6.12.3

22 days ago

6.12.1

28 days ago

6.11.0-pre

6 months ago

6.12.0

5 months ago

6.11.0

5 months ago

6.10.2

8 months ago

6.10.1

8 months ago

6.9.1

9 months ago

6.10.0

9 months ago

6.8.0

1 year ago

6.9.0

1 year ago

6.7.0

1 year ago

6.6.2

2 years ago

6.6.1

2 years ago

6.6.0

2 years ago

6.5.0

2 years ago

6.4.2

2 years ago

6.3.10

2 years ago

6.3.11

2 years ago

6.3.12

2 years ago

6.3.13

2 years ago

6.3.9

2 years ago

6.4.1

2 years ago

6.4.0

2 years ago

6.3.8

2 years ago

6.3.7

2 years ago

6.3.6

2 years ago

6.3.5

3 years ago

6.3.4

3 years ago

6.3.3

3 years ago

6.3.0

3 years ago

6.3.2

3 years ago

6.3.1

3 years ago

6.2.0

3 years ago

6.1.8

3 years ago

6.1.7

3 years ago

6.1.6

3 years ago

6.1.5

3 years ago

6.1.4

3 years ago

6.1.2

3 years ago

6.1.3

3 years ago

6.1.1

3 years ago

6.1.0

3 years ago

6.0.5

3 years ago

6.0.4

3 years ago

6.0.3

3 years ago

6.0.2

3 years ago

6.0.1

4 years ago

6.0.0

4 years ago

6.0.0-rc.10

4 years ago

6.0.0-rc.9

4 years ago

4.15.7

4 years ago

5.15.7

4 years ago

6.0.0-rc.8

4 years ago

6.0.0-rc.7

4 years ago

6.0.0-rc.6

4 years ago

6.0.0-rc.5

4 years ago

6.0.0-rc.4

4 years ago

6.0.0-rc.3

4 years ago

6.0.0-rc.2

4 years ago

4.15.6

4 years ago

5.15.6

4 years ago

5.15.5

4 years ago

4.15.5

4 years ago

6.0.0-rc.1

4 years ago

6.0.0-rc.0

4 years ago

4.15.4

4 years ago

5.15.4

4 years ago

5.15.3

4 years ago

4.15.3

4 years ago

4.15.2

4 years ago

5.15.2

4 years ago

4.15.1

4 years ago

5.15.1

4 years ago

5.15.0

4 years ago

4.15.0

4 years ago

5.14.2

5 years ago

4.14.1

5 years ago

5.14.1

5 years ago

4.14.0

5 years ago

5.14.0

5 years ago

4.13.1

5 years ago

5.13.1

5 years ago

5.13.0

5 years ago

4.13.0

5 years ago

4.12.0

5 years ago

5.11.0

5 years ago

4.11.0

5 years ago

5.10.1

5 years ago

5.10.0

5 years ago

4.10.0

5 years ago

5.9.4-special

5 years ago

5.9.4

5 years ago

4.9.4

5 years ago

4.9.3

5 years ago

4.9.2

5 years ago

4.9.1

5 years ago

5.9.0

5 years ago

4.9.0

5 years ago

4.8.0

5 years ago

5.8.0

5 years ago

5.7.0

5 years ago

4.7.0

5 years ago

4.6.0

5 years ago

5.6.0

5 years ago

4.5.2

5 years ago

5.5.2

5 years ago

4.5.1

6 years ago

5.5.1

6 years ago

5.5.0

6 years ago

4.5.0

6 years ago

4.4.2

6 years ago

5.1.2

6 years ago

4.4.1

6 years ago

5.1.1

6 years ago

5.1.0

6 years ago

4.4.0

6 years ago

5.0.5

6 years ago

5.0.4

6 years ago

4.3.2

6 years ago

5.0.3

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

5.0.0-beta.7

6 years ago

4.3.1

6 years ago

5.0.0-beta.6

6 years ago

5.0.0-beta.5

6 years ago

5.0.0-beta.4

6 years ago

5.0.0-beta.3

6 years ago

5.0.0-beta.2

6 years ago

5.0.0-beta.1

6 years ago

4.3.0

6 years ago

4.2.1

6 years ago

4.2.0

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.2-fix-rn

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.6.2

6 years ago

4.0.0-beta.4

6 years ago

4.0.0-beta.3

6 years ago

4.0.0-beta.2

6 years ago

4.0.0-beta.1

6 years ago

4.0.0-alpha.2

6 years ago

3.6.1

6 years ago

4.0.0-alpha.1

6 years ago

3.6.0

6 years ago

3.5.1

6 years ago

3.5.0

6 years ago

3.4.1

6 years ago

3.4.0

6 years ago

3.3.3

6 years ago

3.3.2

6 years ago

3.3.1

7 years ago

3.3.0

7 years ago

3.2.2

7 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.17

7 years ago

3.1.16

7 years ago

3.1.15

7 years ago

3.1.14

7 years ago

3.1.13-fixcra

7 years ago

3.1.13

7 years ago

3.1.12

7 years ago

3.1.11

7 years ago

3.1.11-rollup

7 years ago

3.1.10

7 years ago

3.1.9

7 years ago

3.1.8-fix874

7 years ago

3.1.8

7 years ago

3.1.7

7 years ago

3.1.6-fix887

7 years ago

3.1.6

7 years ago

3.1.5

7 years ago

3.1.4

7 years ago

3.1.3

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.2-fix798-2

7 years ago

3.0.2-fix798

7 years ago

3.0.1-fix734-2

7 years ago

3.0.2

7 years ago

3.0.1-fix734

7 years ago

3.0.1

7 years ago

3.0.0-fix-751

7 years ago

3.0.0

7 years ago

3.0.0-rc.2

7 years ago

3.0.0-rc.1

7 years ago

2.7.0

7 years ago

2.6.5

7 years ago

2.6.4

7 years ago

2.6.3

7 years ago

2.6.2

7 years ago

2.7.0-beta

7 years ago

2.6.1

7 years ago

2.6.0-fix621

7 years ago

2.6.0

8 years ago

2.5.2

8 years ago

2.5.1

8 years ago

2.5.0

8 years ago

2.5.0-rc1

8 years ago

2.4.4

8 years ago

2.4.3-fix505

8 years ago

2.5.0-alpha1

8 years ago

2.4.3

8 years ago

2.4.2

8 years ago

2.4.1

8 years ago

2.4.0-fix441

8 years ago

2.4.0-fix427

8 years ago

2.4.0

8 years ago

2.4.0-beta1

8 years ago

2.4.0-alpha1

8 years ago

2.3.7

8 years ago

2.3.6-albert

8 years ago

2.3.6

8 years ago

2.3.4-iosfix3

8 years ago

2.3.5

8 years ago

2.3.4-iosfix2

8 years ago

2.3.4-iosfix

8 years ago

2.3.4

8 years ago

2.3.3

8 years ago

2.3.2

8 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.2.2

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.2.0-beta.1

8 years ago

2.1.7

8 years ago

2.1.6

8 years ago

2.1.5

8 years ago

2.1.4

8 years ago

2.1.3

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

0.0.0

8 years ago