Questions tagged [mobx-state-tree]

mobx-state-tree is a state container for javascript apps that is powered by Mobx

209 questions
32
votes
3 answers

Mobx-State-Tree - Assign to Array Type

I have this basic model. const stuff = types.model({ term: types.string, excludeTerm: types.string, stores: types.array(types.string) }).actions(self => ({ setTerm(term: string) { self.term = term }, setExcludeTerm(term: string) { …
etudor
  • 1,183
  • 1
  • 11
  • 19
21
votes
6 answers

MobX vs. MobX State Tree

Why should I use MobX State Tree over vanilla MobX? It seems like any time I read about MobX, MST is mentioned in the same place. Is anyone actually using just MobX by itself? Probably too general of a question...
John
  • 705
  • 3
  • 9
  • 18
15
votes
3 answers

How to get code completion for typed react component properties?

I am using react and mobx-state-tree and I use @inject to inject the stores into my component. So in the end I access the store via this.props.uiStore inside of my component. Unfortunately Visual Studio Code can't infer the type of my store, so I…
stoefln
  • 14,498
  • 18
  • 79
  • 138
11
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
  • 11,067
  • 11
  • 47
  • 90
9
votes
1 answer

Extending a model in mobx state tree

I have a bunch of stores each containing a list of one entity type like const userStore = EntityStore.create(....) const supplierStore = EntityStore.create(....) Some stores can offer additional functionalities, so I wrote const orderStore =…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
8
votes
1 answer

How to make jsDoc "import" work with vscode?

I want to import a node module with @import, but it seems visual studio code is not getting it. Or am I doing it wrong?
stoefln
  • 14,498
  • 18
  • 79
  • 138
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
6
votes
1 answer

Typescript does not infer promise type when using yield in a generator function

I'm using Axios to handle some API fetching, and I'm executing that call within a generator; async/await is not an option for this particular project. For some reason, even though axios is getting my types right, typescript is inferring an any type…
Kevin Whitaker
  • 12,435
  • 12
  • 51
  • 89
6
votes
2 answers

Typed yield expression in MobX-State-Tree flow

The recommended way to do asynchronous actions in MobX-state-tree (MST) is to use flow, which takes a generator function as first argument in which every promise should be yielded. yield expressions are of type any in TypeScript, but is there any…
Tholle
  • 108,070
  • 19
  • 198
  • 189
6
votes
1 answer

How to Persist Mobx State Tree in React Native?

I need to persist a MST Store in React Native. The data is changed seldomly. I'm confused between using AsyncStorage and AutoRun.
Aswin Mohan
  • 952
  • 1
  • 11
  • 26
6
votes
1 answer

mobx-state-tree: How to clone a model that includes references?

I'm trying to clone a model that references another model, but I get: Error: [mobx-state-tree] Failed to resolve reference 'H1qH2j20z' to type 'AnonymousModel' (from node: /usualCustomer)... in the clone. The original resolves okay. Here are my…
user2736142
  • 133
  • 1
  • 5
5
votes
2 answers

Rerender AppNavigator on state change

I am trying to render certain nav stacks depending on a isAuthenticated state. The problem that I am having is that AppNavigator is only rendered on the first render and not with any other changes and I am not sure why. I have tried a useEffect in…
kinzito17
  • 250
  • 2
  • 16
5
votes
1 answer

Why is module.hot.accept handler not called?

I setup HMR in my project and it works fine for most of my application (electron, webpack, react). Only issue: the module.hot.accept callback is never called, so for hot-replacing my data stores, it does not work. I actually wonder that HMR works…
stoefln
  • 14,498
  • 18
  • 79
  • 138
5
votes
4 answers

Confusion between mobx-state-tree and mobx-keystone. When to use which?

Both recommended in the official Mobx page if one wants an opinionated way to using mobx for state management. Based on these(1,2), keystone seems like an improvement of state-tree. Having everything that state-tree has + more. Nowhere I could find…
5
votes
1 answer

async load referenced data in mobx-state-tree

I have looked through the mobx-state-tree documents and even the test file https://github.com/mobxjs/mobx-state-tree/blob/master/packages/mobx-state-tree/tests/core/reference-custom.test.ts#L148 to figure out how to populate a reference node from an…
1
2 3
13 14