Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Full-featured reactive state management without the boilerplate

License

NotificationsYou must be signed in to change notification settings

mobxjs/mobx-state-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

logo

mobx-state-tree

npm versionCircleCIHave a question? Ask on GitHub Discussions!

What is mobx-state-tree?

Technically speaking, mobx-state-tree (also known as MST) is a state container system built onMobX, a functional reactive state library.

This may not mean much to you, and that’s okay. I’ll explain it like this:MobX is a state management "engine", and MobX-State-Tree gives it structure and common tools you need for your app. MST is valuable in a large team but also useful in smaller applications when you expect your code to scale rapidly. And if we compare it to Redux, MST offers better performance and much less boilerplate code than Redux!

MobX isone of the most popular Redux alternatives and is used (along with MobX-State-Tree) by companies worldwide. MST plays very well with TypeScript, React, and React Native, especially when paired withmobx-react-lite. It supports multiple stores, async actions and side effects, enables extremely targeted re-renders for React apps, and much more -- all in a package withzero dependencies other than MobX itself.

Note: you don't need to know how to use MobX in order to use MST.

Getting started

See theGetting started tutorial or follow the freeegghead.io course.

👉 Official docs can be found athttp://mobx-state-tree.js.org/

Quick Code Example

There's nothing quite like looking at some code to get a feel for a library. Check out this small example of an author and list of tweets by that author.

import{types}from"mobx-state-tree"// alternatively: import { t } from "mobx-state-tree"// Define a couple modelsconstAuthor=types.model({id:types.identifier,firstName:types.string,lastName:types.string})constTweet=types.model({id:types.identifier,author:types.reference(Author),// stores just the `id` reference!body:types.string,timestamp:types.number})// Define a store just like a modelconstRootStore=types.model({authors:types.array(Author),tweets:types.array(Tweet)})// Instantiate a couple model instancesconstjamon=Author.create({id:"jamon",firstName:"Jamon",lastName:"Holmgren"})consttweet=Tweet.create({id:"1",author:jamon.id,// just the ID needed herebody:"Hello world!",timestamp:Date.now()})// Now instantiate the store!constrootStore=RootStore.create({authors:[jamon],tweets:[tweet]})// Ready to use in a React component, if that's your target.import{observer}from"mobx-react-lite"constMyComponent=observer((props)=>{return<div>Hello,{rootStore.authors[0].firstName}!</div>})// Note: since this component is "observed", any changes to rootStore.authors[0].firstName// will result in a re-render! If you're not using React, you can also "listen" to changes// using `onSnapshot`: https://mobx-state-tree.js.org/concepts/snapshots

Thanks!

  • Michel Weststrate for creating MobX, MobX-State-Tree, and MobX-React.
  • Infinite Red for supporting ongoing maintenance on MST.
  • Mendix for sponsoring and providing the opportunity to work on exploratory projects like MST.
  • Dan Abramov's work onRedux has strongly influenced the idea of snapshots and transactional actions in MST.
  • Giulio Canti's work ontcomb and type systems in general has strongly influenced the type system of MST.
  • All the early adopters encouraging to pursue this whole idea and proving it is something feasible.

About

Full-featured reactive state management without the boilerplate

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors212


[8]ページ先頭

©2009-2025 Movatter.jp