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
8
votes
1 answer

Error: [MobX] Cannot apply 'observable' to 'Store@user': Field not found

I have a Store: class Store { user!: User; constructor() { makeObservable(this, { user: observable, setUser: action }); } setUser = (user: User | undefined) => this.user = user; } And I'm getting this error: Error:…
gran33
  • 12,421
  • 9
  • 48
  • 76
8
votes
1 answer

Not able to import decorate from mobx

Attempted import error: 'decorate' is not exported from 'mobx'. My mobx version is 6.0, I tried to change the package from mobx to mobx-react, mobx-react-lite,mobx-decorate.But still couldn't resolve it. Thanks in advance Screenshot
Rupa_Sri
  • 81
  • 1
  • 2
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
3 answers

Console log actual variables from MobX store, not Proxy obejcts

Variables fetched from MobX store become Proxy objects in the console. How can we log the actual variable?
remidej
  • 1,428
  • 1
  • 14
  • 21
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
8
votes
3 answers

Detect when mobx observable has changed

Is it possible to detect when an observable changes in any way? For instance, say you have this: @observable myObject = [{id: 1, name: 'apples'}, {id: 2, name: 'banana' }] And later on, with some user input, the values change. How can I detect this…
capvidel
  • 359
  • 3
  • 14
8
votes
1 answer

MobX - Replacing item in observable array?

Please correct me if I am wrong, but currently this is not possible using replace, as replace would replace the entire observable array and map should be used instead? I have an observable array like this: @observable questionsList = []; On server…
Wonka
  • 8,244
  • 21
  • 73
  • 121
8
votes
2 answers

Stateless function components cannot be given refs

I try to access some refs in my component. But I have this error in the console. withRouter.js:44 Warning: Stateless function components cannot be given refs (See ref "pseudo" in FormInputText created by RegisterForm). Attempts to access this ref…
dagatsoin
  • 2,626
  • 6
  • 25
  • 54
7
votes
2 answers

Mobx State Tree reference type and Typescript

I'm using mobx-state-tree with Typescript in a React application. And, I'm having an issue with Typescript where it complains about the type of the mobx type types.safeReference. It looks like the type of safeReference in the model definition is…
ataravati
  • 8,891
  • 9
  • 57
  • 89
7
votes
2 answers

Observable Lists in flutter with mobx

I am trying to make an observable list (i.e. when an element of the list is changed, removed, or added, I would like the UI to updated). I know that mobx has something called an "observableList", and so this seems like it should be possible.…
gollyzoom
  • 519
  • 1
  • 6
  • 21
7
votes
4 answers

React Typescript: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type

I added onChange method in my project(React, TS, Mobx), but I am getting an error: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type I am new to TypeScript and not sure why it's happening. What can be the…
lecham
  • 2,294
  • 6
  • 22
  • 41
7
votes
5 answers

Mobx console warning

I got this waring message from Mobx. [mobx.array] Attempt to read an array index (0) that is out of bounds (0). Please check length first. Out of bound indices will not be tracked by MobX @observable checks = { deviceType: ['phone','laptop',…
kkangil
  • 1,616
  • 3
  • 13
  • 27
7
votes
2 answers

React Hooks (useState) and Mobx [No mobx-react-lite]

in my react application (with typescript) I want to use React hooks (specifically useState) to manage the form state and meanwhile use it as an observable component for Mobx store but I get the error Hooks can only be called inside the body of a…
Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123