0

鉴于以下设置:

import { AppRegistry } from "react-native";
import { Provider } from "mobx-react";
import Application from "./src/components/Application";
import ApplicationStore from "./src/stores/ApplicationStore";
import { name as appName } from "./app.json";

let app = ApplicationStore.create();

AppRegistry.registerComponent(name, () => (
  <Provider app={app}>
    <Application />
  </Provider>
));

ApplicationStore 未定义,因此无法创建...

Cannot read property 'create' of undefined

Module AppRegistry is not a registered callable module (calling runApplication)

有没有更好的方法来设置 ApplicationStore,并通过注入使其可用于组件?

const Application = inject("app")(
  observer(
    class Application extends Component {
    ...

这就是我在反应应用程序()中所做的事情,尽管是通过ReactDOM.render()......

一如既往,所有方向都受到赞赏,所以提前感谢!

4

1 回答 1

0

好的,为胜利尽职尽责!

import React from "react";
import { AppRegistry } from "react-native";
import { Provider } from "mobx-react";
import Application from "./src/components/Application";
import { ApplicationStore } from "./src/stores/ApplicationStore";
import { name as appName } from "./app.json";

const app = ApplicationStore.create();
const ApplicationProvider = () => {
  return (
    <Provider app={app}>
      <Application />
    </Provider>
  );
};

AppRegistry.registerComponent(appName, () => ApplicationProvider);

然后在你的组件内部:

const Application = inject("app")(
  observer(
    class Application extends Component {
      render() {
        return (
          <View style={styles.container}>
            <Text>Application</Text>
          </View>
        );
      }
    }
  )
);

现在商店可用于所有组件并在应用程序启动时实例化......

于 2019-03-28T17:15:13.253 回答