在页面中使用@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文件夹删掉,之后重新启动后可以了。
网友评论