mobx-react

mobx react action binding

拥有回忆 提交于 2020-02-02 13:10:31
问题 For those who has written apps with mobx + react , I'm wondering if there's a better way to handle context issue (eg. this. returns undefined in mobx store) when using onClick event handler inside a react component w/ inject & observer . I have been writing the handler like onClick={actionFromStore.bind(this.props.theStore)} to resolve that issue, but it seems like there should be more concise way to do this that I'm not aware of. I'm not a mobx expert, any advice would be appreciated! The

Using mobx store in react-navigation createStackNavigator

不想你离开。 提交于 2020-01-04 05:20:23
问题 I would like to use Mobx store variable in createStackNavigator in react-navigation. Specifically, I would like to change the initial route dynamically (so that user can change the initial screen) using the store. would this be possible? Something in the line of... const stack = createStackNavigator({ Home:{ ... }, { initialRouteName: this.props.store.initialScreen { }) Because this is not a class, I cannot integrate mobx store. Any ideas to change the initialRoute dynamically is appreciated!

Detect when mobx observable has changed

北战南征 提交于 2020-01-03 12:33:52
问题 Is it possible to detect when an observable changes in any way? For instance, say you have this: @observable myObject = [{id: 1, name: 'apples'}, {id: 2, name: 'banana' }] And later on, with some user input, the values change. How can I detect this easily? I want to add a global "save" button, but only make it clickable if that observable has changed since the initial load. My current solution is to add another observable myObjectChanged that returns true/false, and wherever a component

Mobx Inject, Observer and HoC together

大兔子大兔子 提交于 2020-01-03 02:19:25
问题 Here a code that i have https://jsfiddle.net/v0592ua1/1/ const {observable, computed, extendObservable} = mobx; const {observer, inject, Provider} = mobxReact; const {Component} = React; const {render} = ReactDOM class AppState { @observable authenticated = false; @observable authenticating = false; } class Store2 { @observable blah = false; } function Protected(Component) { @inject("appState") @observer class AuthenticatedComponent extends Component { render() { const { authenticated,

How to export createStackNavigator as class in React Native?

梦想的初衷 提交于 2019-12-24 16:48:08
问题 I read here that using the the createStackNavigator as a Component class was possible, and I was trying to achieve that, but I always got an error. Instead of this: export default createStackNavigator({ Messages }, { defaultNavigationOptions: { gesturesEnabled: false } }) I tried this: class MessagesStack extends React.Component { render() { const RouteConfigs = { Messages }; const NavigatorConfigs = { defaultNavigationOptions: { gesturesEnabled: false } }; const Stack = createStackNavigator

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

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

Store 'someStore' is not available! Make sure it is provided by some Provider

强颜欢笑 提交于 2019-12-23 13:01:44
问题 I am trying to build a new projec twith React, Typescript and MobX. For some reason, i cant get MobX to work. It is a relative simple piece of code, but it gives me this error. Uncaught Error: MobX injector: Store 'appState' is not available! Make sure it is provided by some Provider This is my code: AppState.ts import {observable} from "mobx" import {observer} from "mobx-react" export class AppState { @observable public greeting = "hello World" } index.tsx import * as React from "react"