mobx-state-tree is a state container for javascript apps that is powered by Mobx
Questions tagged [mobx-state-tree]
209 questions
3
votes
2 answers
What's the difference between model and props in `mobx-state-tree`?
It seems to me that people are using model and props interchangeably. I try to find documents about props but failed. Could someone tell me the difference?

Lil E
- 388
- 5
- 23
3
votes
0 answers
Type of image require in React-Native MobX-state-tree: "Possible Unhandled Promise Rejection"
Probably I'm doing it wrong, but what is the type of an "image" in a mobx-state-tree model?
How can I add a property to a MST model in react-native to hold a static image?
const default_img = {
img1: require("./images/01.png"),
img2:…

Guglie
- 2,121
- 1
- 24
- 43
3
votes
1 answer
MobX with React best practice with observer
I'm not really facing an issue, it's more like I'm wondering what is the best way I should use mobx with react. So here's my situation:
I'am fairly new to mobx but I've got years of experience using react (mostly with redux).
My new project is using…

LucasW
- 75
- 7
3
votes
1 answer
Is there dynamic type support?
In MobX state tree, how can I define a property with a dynamic type? ex: can be assigned to any type.. like integer, string, boolean, object, etc
Any idea? Is defining type mandatory in MST ?

simo
- 23,342
- 38
- 121
- 218
3
votes
1 answer
Mobx-state-tree actions not available in visual studio code
While model properties are listed in my visual studio code auto complete, the actions are not. Any idea how this could be improved?

stoefln
- 14,498
- 18
- 79
- 138
3
votes
1 answer
Mobx-state-tree: how to rename AnonymousModel to the store name
i am using mobx-state-tree and i would like to actually show the store name when an error appears instead of AnonymousModel.
For example:
const SignupModel = types
.model({
isUsingFacebook: false,
birthday: '',
timeOfBirth:…

Patrick Klitzke
- 1,519
- 2
- 14
- 24
3
votes
1 answer
Reusable actions in mobx/mobx-state-tree
I have multiple mobx stores and find myself having actions in each of them that are pretty much identical. I'm therefor hoping to be able to generalise and reuse them between stores. Below I have tried to break out the create action hoping to be…

oskare
- 1,061
- 13
- 24
3
votes
2 answers
Get parent data from a child
What way is better? I think than first way is better. Import parent in child looks weird to me, but maybe I'm wrong.
RootStore:
export const RootStore = types
.model('RootStore', {
store1: types.optional(Store1, {}),
store2:…

Pavel
- 2,103
- 4
- 23
- 41
3
votes
1 answer
MobX state tree - array of models doesn't trigger update
I have following model:
const AnotherModel = types.model({
foo: types.string
});
export const SomeCollectionModel = types
.model({
data: types.array(AnotherModel),
})
.views((self) => ({
getData: () =>…

Łukasz Ostrowski
- 960
- 4
- 12
- 25
3
votes
1 answer
Using mobx store only outside of the react components render function
I have a react component that wraps a class that renders WebGL using three.js with the DOM and connects mobx store value and it changes with the class lifecycle methods.
The passed in mobx store is only used outside of the components render function…

Renārs Vilnis
- 1,160
- 1
- 10
- 24
3
votes
2 answers
Where should "Toasts" live in Mobx State Tree?
My async actions tend to look something like this:
anAsyncAction: process(function* anAsyncAction() {
self.isLoading = true;
const service = getEnv(self).myService;
try
{
yield service.doSomething();
…

mikeysee
- 1,613
- 1
- 18
- 31
2
votes
1 answer
typescript get "typeof" Generic class inside type declaration
I'm trying to make a custom hook that gets 2 parameters:
1- a class that's actually is a mobx store
2- parameters of that class constructor
this hook is lookalike this in javascript:
/**
* @template T
* @param {new() => T} Store
* @param {any[]}…

javad bat
- 4,236
- 6
- 26
- 44
2
votes
1 answer
Cannot add an object to a state tree if it is already part of the same or another state tree
mobx-state-tree.module.js?f7d3:2154 Uncaught Error: [mobx-state-tree] Cannot add an object to a state tree if it is already part of the same or another state tree.
I get this error just by filtering through another state:
const data =…

Rollin
- 304
- 4
- 13
2
votes
1 answer
Is there any way to cancel previous async action in mobx-state-tree (Similar to takeLatest in redux-saga)
Currently, I am working on my react-native application using MST as a state management library.
Now I have encountered an issue where the app has a chance to fire 2 similar API calls. The 1st API responded after the 2nd one, which caused the data to…

Tony Fung
- 1,222
- 1
- 11
- 15
2
votes
1 answer
Firebase + Typescript - issue with ID property and withConverter (creating an new Document that don't have ID property)
Let me try to explain the situation:
To create an new document in firestore, I'm using add method from collection
To keep type safe, using typescript, I'm using withConverter
When I'm creating an new document, I don't have ID property on my…

ridermansb
- 10,779
- 24
- 115
- 226