美文网首页
react-native中使用mobx-react

react-native中使用mobx-react

作者: 溜溜的阳光 | 来源:发表于2019-08-05 23:15 被阅读0次

在页面中使用@inject时候

/**

* Sample React Native App

* https://github.com/facebook/react-native

*

* @format

* @flow

*/

// import React, {Fragment, Component} from 'react';

// import { observer, inject } from "mobx-react";

// import { Container } from "native-base";

// import {

//  StyleSheet,

//  Button,

//  Text

// } from 'react-native';

//

// @inject(["homeStore"]) // 注入对应的store

// @observer // 监听当前组件

// export default class Page1 extends Component{

//  constructor (props) {

//    super(props)

//    this.store = this.props.homeStore; //通过props来导入访问已注入的store

//

//  }

//  render () {

//    const { text, num } = this.store;

//    const {navigation} = this.props

//    return (

//     

//        welcome to page1

//        {

//          navigation.goBack()

//        }}/>

//        {

//          navigation.navigate('Page4')

//        }}/>

//        this.store.plus()} />

//        {num}

//        this.store.minus()} />

//     

//    );

//  }

// };

模拟器报了Expected a constructor的错误

谷歌了一下https://github.com/mobxjs/mobx-react/issues/690在这个链接里面找到原因

原因是rn版本在0.60以上有这个问题,好像是react-proxy导致的

后来把mobx-react 6.0版本降级到了5.4.4版本

把ios里面的build文件夹删掉,之后重新启动后可以了。

相关文章

网友评论

      本文标题:react-native中使用mobx-react

      本文链接:https://www.haomeiwen.com/subject/rgqbdctx.html