mobx

MobX - Observable value promised in a store constructor using fromPromise stays null when accessed in another store?

怎甘沉沦 提交于 2020-01-02 06:25:13
问题 So I have 2 stores, an AuthorStore : class AuthorStore { constructor() { // has author.name and is always present in storage AsyncStorage.getItem('author').then(action((data) => { this.author = JSON.parse(data); })); } @observable author = null; } and a BookStore : import AuthorStore from 'authorStore'; class BookStore { @observable book = { authorName: AuthorStore.author.name, bookTitle: null } } I keep getting an error in BookStore that it cannot get property of null , as if the AuthorStore

MobX - Observable value promised in a store constructor using fromPromise stays null when accessed in another store?

我是研究僧i 提交于 2020-01-02 06:25:10
问题 So I have 2 stores, an AuthorStore : class AuthorStore { constructor() { // has author.name and is always present in storage AsyncStorage.getItem('author').then(action((data) => { this.author = JSON.parse(data); })); } @observable author = null; } and a BookStore : import AuthorStore from 'authorStore'; class BookStore { @observable book = { authorName: AuthorStore.author.name, bookTitle: null } } I keep getting an error in BookStore that it cannot get property of null , as if the AuthorStore

Rerender component as mobx store is updated

让人想犯罪 __ 提交于 2019-12-24 21:01:38
问题 I am using chart.js to show price changes from the backend in real time. Backend sends a new price when it is changed to frontend . priceData (array) is saved in mobx priceChartStore . I have to update chart as price is changed. I use ref value of canvas tag to draw price chart. The problem is that the componentDidUpdate function is not called unless I call that priceData value in render function,even though It isn't used in render function. It works: componentDidUpdate() { const {

Failed prop type: Invalid prop `onClick` of type `object` supplied to `ButtonBase`, expected `function`

天涯浪子 提交于 2019-12-24 15:41:59
问题 <Fab raised="true" size="small" color="primary" variant="extended" onClick={props.Store.fetchFromServer} and this.fetchFromServer = async () => { await console.log('test') } works fine. But when changed to following <Fab raised="true" size="small" color="primary" variant="extended" onClick={props.Store.fetchFromServer('test')} and this.fetchFromServer = async (val) => { await console.log(val) } throw following error, what I am missing? Failed prop type: Invalid prop `onClick` of type `object`

Why should MobX not be used as a State Container?

馋奶兔 提交于 2019-12-24 09:09:37
问题 Why should MobX not be used as a State Container? as mentioned in the official docs "MobX is not a state container"? Isn't is like Redux? 回答1: Redux is better compared with MobX State Tree I, considering the similar action dispatch pattern, tooling etc. MobX does not provide any restrictions on how new states can be derived from old ones. It's more of a Data flow library as its creator likes to call it. MobX helps us set up Reactivity outside React components. This way view components can be

React Native Mobx null pointer dereference

混江龙づ霸主 提交于 2019-12-24 04:02:37
问题 I'm using mobx (and mobx-persist) as my react native app global store (I'm using expo client). First I fetch some data from the server then i save the results in the store and persist them in asyncStorage. It was working fine at first but then suddenly when I try to login the app freezes then crashes with summary containing "Cause: null pointer dereference". Following is my code. The store code: import { observable, computed, action, set } from 'mobx'; import { create, persist } from 'mobx

Improve poor progress bar performance

眉间皱痕 提交于 2019-12-24 03:42:07
问题 I am trying to pass progress state to other progress bar by using the MobX store. There are two progress bars. One of them should be changing independently in a short period(about 2secs). I used setTimeOut to increase the current progress and it worked well. Then I tried to save the current progress value into the MobX store to pass to another component. After this, the performance of the progress bar was degraded. render() { ... if (tradingProgress.progress > 100) { this.setState(prevState =

Injecting Store in React component results in Error

被刻印的时光 ゝ 提交于 2019-12-24 03:27:50
问题 I am trying inject a store to my React Component however I am getting the following error: Undefined is not a function (evaluating 'decorator(target,property,desc)') In my App.js I have: import React, { Component } from 'react'; import PoolComponent from './app/Components/PoolComponent'; import MeasurementsStore from './app/Stores/MeasurementsStore'; export default class PoolApp extends Component { render() { return ( <PoolComponent store="MeasurementsStore"/> ); } } In my PoolComponent.js

How can I clone a MobX observable? (edit save changes)

﹥>﹥吖頭↗ 提交于 2019-12-23 11:48:56
问题 I have a simple react form, and two observables in my MobX store: @observable personalInfo = { email: '', gender: 1, birthDate: null, location: '' }; @observable personalInfoInEdit = null; When the form of the personal info is loaded (in the ctor) I am calling a method on my store: reset_PersonalInfoInEdit() { this.personalInfoInEdit = observable(this.personalInfo); } What it dose is simply reseting the "in edit" object, filling it with data from the original data. If the user press "save

How can I clone a MobX observable? (edit save changes)

别等时光非礼了梦想. 提交于 2019-12-23 11:47:16
问题 I have a simple react form, and two observables in my MobX store: @observable personalInfo = { email: '', gender: 1, birthDate: null, location: '' }; @observable personalInfoInEdit = null; When the form of the personal info is loaded (in the ctor) I am calling a method on my store: reset_PersonalInfoInEdit() { this.personalInfoInEdit = observable(this.personalInfo); } What it dose is simply reseting the "in edit" object, filling it with data from the original data. If the user press "save