React-native + mobx Index.js 应该是什么样子

React-native + mobx how the Index.js should look like

我正在尝试将 Mobx(老实说,我是 Mobx 的新手)集成到我现有的 react-native 项目中,我的一个大问题是索引文件应该是什么样子?

我的现在看起来像这样:

Index.js:

import { AppRegistry } from 'react-native';
import App from './../App/App';

AppRegistry.registerComponent('AppName', () => App);

但是一些教程告诉我它应该是这样的:

Index.js:

 {a bunch of imports here...}
 ReactDOM.render(
   <Provider store={store}>
     <App />
   </Provider>,
  document.getElementById('root')
);

但我没有得到第二个运行。

所以我的问题是 index.js 应该是什么样子?

AppRegistry.registerComponent 接受一个 returns 组件的函数,因此如果您让该组件呈现 Provider,它应该可以工作。

const Root = () => (
  <Provider {...stores}>
    <App />
  </Provider>
)

AppRegistry.registerComponent('AppName', () => Root)