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

1624 questions
7
votes
2 answers

Error: [mobx-state-tree] Failed to resolve reference XXX to type 'User'

Context I have a React application that is backed by mobx-state-tree (MST). One of the pages makes two parallel API calls to fetch a list of Projects and a list of system Users. The responses of these two APIs are then applied as snapshot to two…
Igor Soloydenko
  • 7,161
  • 7
  • 39
  • 73
7
votes
1 answer

MobX - Why should I use `observer` when I could use `inject` when injecting data into a React component

MobX documentation suggests I should use observer on all my components. However by using inject I get more fine grained control over what data causes a re-rendering of my components. My understanding is I that with observer, a change in all accessed…
Mateo Hrastnik
  • 473
  • 6
  • 18
7
votes
2 answers

Mobx changing observable values outside of action

I'm getting the following error: proxyConsole.js:54 Error: [mobx] Invariant failed: Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended.…
user818700
7
votes
1 answer

Component disappears on update

I am implementing a word search facility in my React Native app. I have a MobX store, wordStore. Each text change triggers a database query via the setFilter action. This all works under the hood as I can see from console debug output. However, the…
Adamski
  • 3,307
  • 2
  • 29
  • 72
7
votes
1 answer

How to test react components with mobx observable state

Here is a simplified version of my component: import React from 'react'; import { observable, action } from 'mobx'; import { observer } from 'mobx-react'; import { fromPromise } from 'mobx-utils'; @observer export class MyComponent extends…
alisabzevari
  • 7,178
  • 6
  • 38
  • 60
6
votes
2 answers

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
  • 61
  • 1
  • 2
6
votes
3 answers

React native + Mobx, @inject decorator throws an error

I'm trying to use mobx with react native and stuck into a problem. @inject('someStore') @observer export class SomeComponent extends Component { render() { ... } } I'm sure I configured properly babel plugins for decorator but @inject…
jesuisgenial
  • 599
  • 4
  • 13
6
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
  • 3,249
  • 4
  • 40
  • 86
6
votes
1 answer

Importing CSS variables into a Typescript file

We created a theme.css :root file with a number of commonly used variables to use across the various other .css files for our app. But some of our older code has a similar setup, but in a theme.ts file with some variables. I want to import the…
mdb
  • 159
  • 2
  • 13
6
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
  • 407
  • 5
  • 19
6
votes
1 answer

How to use mobx-react 'observer' without decorator syntax?

I am trying to shoe horn mobx into a vr application I am making with react 360. I've tried to use the decorator syntax but after wasting a solid chunk of time trying to implement it, I've decided to use the nondecorator syntax. Here is an example…
Dan Rubio
  • 3,965
  • 5
  • 34
  • 74
6
votes
1 answer

Support for the experimental syntax 'decorators-legacy' isn't currently enabled

I am getting the above error when I am using mobx-react and while trying to use annotations.Here I am using .js and not .ts. All the solutions provided earlier not successful for me. import React, { Component } from 'react'; import { withRouter,…
6
votes
1 answer

React-Mobx Warning: A component is changing an uncontrolled input

I use React + TypeScript + Mobx. I made the form with input, everything is working, but the browser gives an error. What am I doing wrong? Warning: A component is changing an uncontrolled input of type text to be controlled. Input elements should…
cooperJCW
  • 65
  • 3
6
votes
3 answers

Mobx @computed functions with parameters

I'm new to Mobx but so far it's been working great and I've managed to get pretty far. I have a react-native application with mobx, and mobx-persist. I'm using axios to pull posts from a Wordpress site. The functionality that I'm trying to improve…
6
votes
1 answer

React/Mobx - component is re-rendering, but componentWillReceiveProps() is not being called

I have React/Mobx app. When I am making changes in the store, the component is updating (re-rendering), but I need to make some comparisons for adding some more functionality, so I want to use componentWillReceiveProps(nextProps) and compare…
Hayk Aghabekyan
  • 1,057
  • 10
  • 18