mobx-state-tree is a state container for javascript apps that is powered by Mobx
Questions tagged [mobx-state-tree]
209 questions
5
votes
2 answers
How to deal with inconsistent mobx-state-tree snapshots?
I am writing an electron app and I keep all my app data inside a single MST tree.
Now I noticed that every now and then you run into a situation where data becomes inconsistent (missing reference object etc).
While this can happen with any type of…

stoefln
- 14,498
- 18
- 79
- 138
5
votes
1 answer
How to describe model of mobx-state-tree with interface of typescript?
I have some interfaces already, and I want to describe models with this interfaces, just like the code below. Otherwise I have to write again by using types of mobx-state-tree. But this is not the right way, what is the valid solution ?
import…

马邦德
- 103
- 1
- 9
5
votes
0 answers
Mobx-state-tree SSR double init client and server
I use mobx-state-tree on my NextJS app with Server Side Rendering. On the server only, I fetch an API to load some information and add to my Store. But after the client load, my store is cleared because I need to instantiate on server AND client.…

s-leg3ndz
- 3,260
- 10
- 32
- 60
5
votes
3 answers
How to have a nullable string value in Mobx-State-Tree
I'm trying to create a model with a optional, nullable string value.
I've tried using both
hint: types.optional(types.string, ""),
and
hint: types.maybe(types.string),
Both results in error when I try to set a json object as to the…

AbsoluteSith
- 1,917
- 25
- 60
5
votes
1 answer
How to Change Parent State from Child - Mobx State Tree?
I am trying to make a Nav in reactjs with Mobx State Tree.
Right now I have skinny vertical Nav bar with a list of icons. Now what I want to do is add sub menu items to certain ones. When these ones are clicked the Nav goes from skinny to wide(ie…

chobo2
- 83,322
- 195
- 530
- 832
4
votes
1 answer
How to convert datetime string to date object via mobx-state-tree properly
there is incoming string data which is date time format,
Its mapping this object fine;
import { types } from 'mobx-state-tree'
export const UserCard = types.model('UserCard').props({
id: types.number,
awarded_at:…

TyForHelpDude
- 4,828
- 10
- 48
- 96
4
votes
3 answers
Support for the experimental syntax 'decorators-legacy' isn't currently enabled How To Enable In Create React App?
I am trying to get up and running with react create app and mobx state tree. I keep getting
Support for the experimental syntax 'decorators-legacy' isn't currently enabled (4:1):
I never used react create app so I am not sure how to enable, I…

chobo2
- 83,322
- 195
- 530
- 832
4
votes
2 answers
How to create types.array in MST from external api - always returning proxy not object
I'm fetching data from external API, and want to store it in MST store as array. But the result is always proxy, not the object I wanted.
This is result from API:
(4) [Object, Object, Object, Object]
0:Object
id:1
name: "Foobar"
created_at:…

Nico Audy
- 77
- 6
4
votes
2 answers
How To Split Mobx State Tree Models Across Multiple Files?
I have a Mobx State Tree model that has grown too long and I would like to split it across multiple javascript files.
Here is a demo of some of the code:
///file1.js
import { types } from "mobx-state-tree";
export const ExampleModel =…

Alexander Perls
- 123
- 2
- 9
4
votes
3 answers
Ensuring interface compliance in MobX State tree models
I have interfaces defined for my typescript server APIs and when defining models through MobX state tree I would like to ensure that the typescript compiler enforces that the model snapshots comply with these interfaces.
So if an additional…

lorefnon
- 12,875
- 6
- 61
- 93
3
votes
1 answer
Cannot copy mst model data from one model to other
I'm trying to make a news app which can take response from news api and store it in newsFeed and then user can mark some news as favourites and then store these fav to new model favourite
this is the error i'm getting
Error: [mobx-state-tree] Cannot…

lazycoder
- 43
- 5
3
votes
1 answer
Mobs-state-tree action fails due to protection
In the following store I try to upload some photos and want to update the UI with the progress. This is my main store:
const Store = types
.model({
photos: types.array(Photo),
isLoading: false,
})
.actions((self) => {
return {
…

MisterPalace
- 31
- 1
3
votes
1 answer
How to populate mobx-state-tree map from existing object
This is a simplified version of my Store. I want to initialise it with data coming from json.
However, typescript keeps bothering me with errors.
const DistrictModel = types.model('District', {
id: types.string,
name: types.string,
borders:…

publicJorn
- 2,404
- 1
- 20
- 30
3
votes
1 answer
mobx-state-tree error while converting to anonymousModel
What should happen - succesfully create RootStore from defaultSnapshot and reset it when needed, successful backcuping in localStorage.
What happens - getting an error while trying to apply a snapshot, when attempting to open page, just by running…

bpalij
- 301
- 4
- 9
3
votes
1 answer
types.reference not resolving the reference in mobx-state-tree
I am writing a search function that returns an array of ModelA or ModelB but when I use the references in my component, the reference is still a string. From the docs, I was expecting this to be the actual ModelA or ModelB so I feel like I am doing…

Special Character
- 2,321
- 4
- 25
- 34