Questions tagged [mobx-react]

MobX is a battle-tested library that makes state management simple and scalable

React and MobX together are a powerful combination. React renders the application state by providing mechanisms to translate it into a tree of renderable components. MobX provides the mechanism to store and update the application state that React then uses.

Both React and MobX provide optimal and unique solutions to common problems in application development. React provides mechanisms to optimally render UI by using a virtual DOM that reduces the number of costly DOM mutations. MobX provides mechanisms to optimally synchronize application state with your React components by using a reactive virtual dependency state graph that is only updated when strictly needed and is never stale.

850 questions
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
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

What are the advantages and disadvantages of mobx and Redux, particularly in a React-Native environment?

Lately I've been hearing everyone talking about mobx, I've used (am using) Redux in a production React Native application. I'm just looking to see if anyone has experience with both and can advise where each one holds advantages over the other.
R. Langford
  • 163
  • 1
  • 8
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
11
votes
4 answers

React: Don't render components in table who aren't visible

I have a table with >30 rows and >50 columns. Each row and each cell is a specific React component, since you can manipulate them and they change behaviour and look based on changing data. So my component hierachy looks like this: Grid -> Row ->…
Johannes Klauß
  • 10,676
  • 16
  • 68
  • 122
10
votes
1 answer

How to get a plain object from mobx object?

I defined a mobx map as below: @observable editors = observable.map(); then I added object on the editors as below: editors.set(key, { alias: 'alias-1', message: 'hello', }) when I get the object from editor as below: let myEditor =…
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
10
votes
3 answers

React + Mobx: 'this' is null when trying to update store

Just getting started with Mobx & React and having trouble getting the store to update. I get error when clicking the button, which should update the 'me' property: Store.js:12 Uncaught TypeError: Cannot set property 'me' of null My store: import {…
Chris
  • 1,557
  • 5
  • 19
  • 36
9
votes
5 answers

Is it possible to use React Hooks outside of functional component, or i have to use mobx or redux?

I am new to React, and when I was reading about the docs, I found there were two ways to implement React components, functional-based and class-based. I know before React 16.8 it's not possible to manage state in functional components, but after…
apporc
  • 870
  • 3
  • 11
  • 23
9
votes
1 answer

Make typescript see props from decorators

I have simple component that uses mobx and decorators like this import * as React from "react"; import { observer, inject } from "mobx-react/native"; import { Router as ReactRouter, Switch, Route } from "react-router-native"; import Dashboard from…
Ilja
  • 44,142
  • 92
  • 275
  • 498
8
votes
1 answer

react mobx - store return Proxy object

I have the following state class: import { observable, action } from 'mobx'; import axios from 'axios'; export default class AppState { @observable user; @observable pToken; constructor() { this.user = {}; this.pToken =…
TheUnreal
  • 23,434
  • 46
  • 157
  • 277
8
votes
1 answer

MobX 'this' is undefined in setter action

I am using a recent create-react-app setup with JS and the mobx decorate method. import { observable, action, decorate } from 'mobx' class UserStore { users = [] currentUser = {} setUsers(value) { this.users = value …
janniks
  • 2,942
  • 4
  • 23
  • 36
8
votes
1 answer

Access stores from class using mobX and react Context

I am strugling a bit with mobx/mobx-react-lite and react hooks. From a class i want to update a property in one of my stores, but somehow i cant get it to work. Here are some examples of how my stores are combined, and the component and class i…
Englund0110
  • 514
  • 2
  • 5
  • 23
8
votes
1 answer

Store 'someStore' is not available! Make sure it is provided by some Provider

I am trying to build a new projec twith React, Typescript and MobX. For some reason, i cant get MobX to work. It is a relative simple piece of code, but it gives me this error. Uncaught Error: MobX injector: Store 'appState' is not available! Make…
Englund0110
  • 514
  • 2
  • 5
  • 23
8
votes
3 answers

How can I access mobx store in another mobx store?

Assume following structure stores/ RouterStore.js UserStore.js index.js each of ...Store.js files is a mobx store class containing @observable and @action. index.js just exports all stores, so import router from "./RouterStore"; import user…
Ilja
  • 44,142
  • 92
  • 275
  • 498
1
2
3
56 57