我正在尝试使用 react-native-navigation 和 redux persistStore 中的 persistStore 启动我的应用程序。我收到警告说函数作为 React 子级无效。如果您返回一个组件而不是从渲染中返回,则可能会发生这种情况。
是否有任何解决方法来启动这个初始屏幕,最近我添加了 startApp 函数并在渲染中调用它。
这是我启动应用程序的初始组件:
import React, { Component } from "react";
import { Provider } from "react-redux";
import { View, Text } from "react-native";
import { persistStore } from "redux-persist";
import { Navigation } from "react-native-navigation";
import Mapbox from "@mapbox/react-native-mapbox-gl";
import { registerScreens } from "./screens";
import store from "./store/configureStore";
import { appInit, getInitialScreen } from "./appInit";
import { handleErrorObject } from "./lib/handleError";
Mapbox.setAccessToken("pk.eyJ123425KKbcgNww");
export default class App extends Component {
startApp = () => {
const persistor = persistStore(store, null, () => {
registerScreens(store, Provider);
appInit(store)
.then(() => {
const initialScreen = getInitialScreen(store.getState());
Navigation.startSingleScreenApp({
screen: {
screen: initialScreen
},
passProps: {
persistor
},
drawer: {
left: {
screen: "DrawerMenuScreen"
}
},
appStyle: {
orientation: "portrait"
}
});
})
.catch(error => {
handleErrorObject("Error initializing app", error);
});
});
};
render() {
return <View>{this.startApp}</View>;
}
}