mobx-react

MobX + React Native : way to inject stores

霸气de小男生 提交于 2019-12-22 08:14:17
问题 I'm trying to work with MobX for a new project. I started it on May 2017, and everything was working well. I had to stop, and now I go on developing it. I had to make an npm install to manage making it working, but now, I have some problem with stores... I rely on this tutorial for the structure : https://blog.callstack.io/write-react-native-apps-in-2017-style-with-mobx-e2dffc209fcb This is my structure : Main index.js import { Provider } from 'mobx-react'; import Stack from './router';

Can't call setState on a component that is not yet mounted

可紊 提交于 2019-12-18 05:43:26
问题 this is the first time I face this warning message. Can't call setState on a component that is not yet mounted. Follows: This is a no-op, but it might indicate a bug in your application. Instead, assign to this.state directly or define a state = {}; class property with the desired state in the MyComponent component. The " not yet mounted " part actually makes little to no sense as the only way to trigger the issue is to call a function by clicking a button from a component that needs to be

Correct way of Creating multiple stores with mobx and injecting it into to a Component - ReactJs

无人久伴 提交于 2019-12-18 02:57:28
问题 As suggested here in the Mobx documentation I have created multiple stores in the following manner: class bankAccountStore { constructor(rootStore){ this.rootStore = rootStore; } ... class authStore { constructor(rootStore){ this.rootStore = rootStore; } ... And finally creating a root store in the following manner. Also I prefer to construct children stores within master's store constructor. Moreover, I found that sometimes my child store has to observe some data from parent store, so I pass

React-MobX Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean

最后都变了- 提交于 2019-12-12 07:44:56
问题 I get the following error: If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the 'decorators-legacy' plugin instead of 'decorators'. package.json "@babel/plugin-proposal-decorators": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-decorators/-/plugin-proposal-decorators-7.1.2.tgz", "integrity": "sha512-YooynBO6PmBgHvAd0fl5e5Tq/a0pEC6RqF62ouafme8FzdIVH41Mz/u1dn8fFVm4jzEJ+g/MsOxouwybJPuP8Q==", "requires": {

react getting observable values in component

别等时光非礼了梦想. 提交于 2019-12-12 03:09:14
问题 Seting the obsrv array in the component below; class AnnouncementState { @observable categories =[]; constructor(){ this.getAnnouncementCategory(); } getAnnouncementCategory() { fetch(`..`) .then((response) => { return response.json(); }) .then((response) => { this.categories = response.value.map((item , i)=>{ return {Id:item.Id, Title:item.Title} }); }, (error) => { }); } } I checked the retrieved values its ok. and I try set it in component and render it below; @observer class

React Native mobx binding to FlatList not working

痞子三分冷 提交于 2019-12-11 13:30:04
问题 I have a RN (0.44.2) mobx (3.1.10) app which uses a FlatList . I'm basically following https://blog.callstack.io/write-react-native-apps-in-2017-style-with-mobx-e2dffc209fcb When using my own store, opposed to the examples, I'm having to use toJS() in order to get the FlastList to render // renders list <FlatList data={this.props.giphyStore.images.toJS()} keyExtractor={(_, i) => i} renderItem={({ item }) => <Text>found the data</Text>} /> // does not render list <FlatList data={this.props

handleChange with React and Mobx

大兔子大兔子 提交于 2019-12-11 08:13:17
问题 On Step 2 of my web app, an observable string value is assigned inside a MobX store. It is then rendered as a textarea value when the Step 3 component render is triggered. I have been following the React docs at https://reactjs.org/docs/forms.html to handle manual changes to the textarea value but have not been successful. My textarea in the Step 3 functional component (imported from Semantic UI React): <TextArea autoHeight value={ ui_store.final_text_message } className={ textarea_style }

Mobx Observable Array not updated

限于喜欢 提交于 2019-12-11 02:29:45
问题 I am declaring a observable array in the following way in reactjs using mobx @observable cacheditems constructor() { this.cacheditems = [] Now I am retrieving the data from pouch-db when offline as follows: var items = [] db.allDocs({include_docs: true}, function(err, docs) { docs.rows.map((obj, id) => { items.push(obj.doc) }) }) this.cacheditems = items But the data is not set. When I try to get the data for rendering its a empty array. 回答1: When you do this.cacheditems = items you are

No chance to make an strongly typed object observable by mobx

与世无争的帅哥 提交于 2019-12-11 00:38:43
问题 I use mobx library. It fit well with ReactJS. I have and observable array like this: @observable items = []; When I add an object in this way, I have no problem and the given object will be observable as expected. let x = { Title: "sample title" } items.push(x); but when I define an strongly typed object (using typescript) export class SampleObject { Title: string; constructor(title: string) { this.Title = title; } } and pushing new object in this way, It won't be observable items.push(new

undefined is not a function (evaluating 'decorator(target, property, desc)')

寵の児 提交于 2019-12-10 14:26:58
问题 I want to integrate mobx and mobx-persist with react-navigation. I read these articles: [1] https://hackernoon.com/react-navigation-with-mobx-2064fcdaa25b [2] https://blog.callstack.io/write-react-native-apps-in-2017-style-with-mobx-e2dffc209fcb [3] https://github.com/react-navigation/react-navigation/blob/8e8d3d562c9e80616f145f97ffb02dcf2048e67e/docs/guides/Mobx-Integration.md [4] MobX + React Native : way to inject stores [5] MobX - Why should I use `observer` when I could use `inject` when