Questions tagged [mobx]

Functional reactive programming library in JavaScript.

About

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

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

which includes the UI, data serialization, server communication, etc.

Links

1876 questions
16
votes
2 answers

Does MobX Observables have anything to do with RxJS ones?

The title is pretty much self explaining. I can't find any info about it. Angular uses RxJs observables under the hood is the same going on in React and MobX particularly?
Davit Karapetyan
  • 589
  • 1
  • 6
  • 14
15
votes
9 answers

How to get MobX Decorators to work with Create-React-App v2?

Support for the experimental syntax 'decorators-legacy' isn't currently enabled I tried adding the decorators-legacy babel plugin and @babel/plugin-proposal-decorators with { legacy: true } in .babelrc but no effect. Anyone managed to get MobX…
J. Reku
  • 509
  • 1
  • 5
  • 15
15
votes
3 answers

Using the MobX @action decorator with async functions and .then

I'm using MobX 2.2.2 to try to mutate state inside an async action. I have MobX's useStrict set to true. @action someAsyncFunction(args) { fetch(`http://localhost:8080/some_url`, { method: 'POST', body: { args } }) .then(res…
twsmith
  • 401
  • 4
  • 15
15
votes
2 answers

Mobx: Observable array does not display correctly

I am trying to understand how to use observable array with Mobx. I have a hard time to figure out why this: let entities = observable([]); entities[0] = "foo"; autorun(() =>{ console.log(entities); }); writes: [$mobx: Object] 0: (...) 1: (...) 2:…
dagatsoin
  • 2,626
  • 6
  • 25
  • 54
14
votes
2 answers

How to use mobx in react-native 0.56 (Babel 7) with Decorators

i've upgraded my RN app from 0.55.4 to 0.56 that use Babel 7. In 0.55.4 to use decorators for MOBX i use "babel-plugin-transform-decorators-legacy" but is not compatible with Babel 7... react-native ver: 0.56.0 mobx ver: 5.0.3 mobx-react ver:…
14
votes
1 answer

MobX Mutability vs Immutability

Why MobX encourage mutable objects in their docs?? But, I see a tutorial about MobX: http://orlandohamsho.com/javascript/mobx-react-tutorial-building-first-application/ And, he used immutable approach in his tutorial instead of mutable one (see…
Terry Djony
  • 1,975
  • 4
  • 23
  • 41
14
votes
1 answer

How to track nested object in a MobX store

Let's stay I have this myObject loaded via an API call: myObject = { fieldA: { details: 'OK', message: 'HELLO' }, fieldB: { details: 'NOT_OK', message: 'ERROR' }, } Only details and message of each field can change. I want this object to be…
jeanpaul62
  • 9,451
  • 13
  • 54
  • 94
14
votes
4 answers

How to save Mobx state in sessionStorage

Trying to essentially accomplish this https://github.com/elgerlambert/redux-localstorage which is for Redux but do it for Mobx. And preferably would like to use sessionStorage. Is there an easy way to accomplish this with minimal boilerplate?
anthony-dandrea
  • 2,583
  • 7
  • 26
  • 46
13
votes
1 answer

Difference between mobx's `action.bound` and arrow functions on class functions?

Using arrow functions on a class with babel transpiles it so the definition is bound in the constructor. And so it is not in the prototype and it is not available via super when inheriting. It is also not as efficient when scaling by creating many…
bitten
  • 2,463
  • 2
  • 25
  • 44
13
votes
1 answer

What is the best way to create a single MobX store for an app?

I have been using MobX and Redux for about 6 months. I have found that I prefer the simplicity of MobX for most applications. However, I like the single store concept of Redux. I have heard others comment that they create a single story with MobX…
Tanner Plauché
  • 163
  • 1
  • 10
12
votes
3 answers

What exactly does mobx-react-lite's "useLocalStore" hook do, and why is it (only sometimes) needed?

Within the mobx-react documentation there are variations in how stores are created. For example, on the React Context page: In the first code sample, the store is instantiated with useLocalStore: const store = useLocalStore(createStore) In the…
arhnee
  • 1,044
  • 9
  • 24
12
votes
5 answers

React Native component opacity not updating when props updated

I have a React Native child component, which renders a button in a semi-transparent state if the disabled prop is set to true. The prop is likely to be updated after the app initially loads (once it has got its data), so will not be the initial…
Adamski
  • 3,585
  • 5
  • 42
  • 78
12
votes
8 answers

React not rerendering after mobx observer change

Upon page load, I see "hi2" When I click the button, nothing happens. I tried with setUser as well. I suspect I'm just editing the props themselves and somehow the observable is not being triggered? See sample code of it not working here in a brand…
wiznaibus
  • 661
  • 3
  • 8
  • 17
12
votes
2 answers

All table rows re-render after selection changes

I have table of customers and the selected customer is stored in the ViewState. The problem is that all rows re-render when the selection changes which is quite slow. Ideally only the selected row and the row previously selected would re-render, but…
jpfollenius
  • 16,456
  • 10
  • 90
  • 156
12
votes
4 answers

React Mobx - component not updating after store change

Using Mobx, after updating the store (i.e. clicking the button) the component does not re-render. I've installed mobx devtools which shows nothing after the initial load, and there is no error in the console. Any ideas what I've done…
Chris
  • 1,557
  • 5
  • 19
  • 36