【发布时间】:2017-06-15 08:48:36
【问题描述】:
我是 Ract Native 的新手,我正在尝试使用 react native 导航构建一个小应用程序。
我可以在他们网站上提供的电影应用示例(反应原生导航)中看到,他们没有在 app.js 中使用 componentWillMount 函数,而是在构造函数中调用了 startApp() 函数。
我基本上是想在 componentWillMounth 函数中定义 firebase 配置,但是一个简单的控制台日志显示该函数不知何故永远不会运行。
我想正确设置应用程序,以获得最佳性能,所以我想知道使用 startApp 功能是否基本相同,不需要使用 componentWillMount 功能?
更新:以下代码
index.ios.js
import App from './src/app';
const app = new App();
app.js
import ...
class App extends Component {
state = {
loggedIn: null
}
constructor(props) {
super(props);
this.startApp();
}
componentWillMount() {
console.log('COMPONENT WILL MOUNT');
// Initialize Firebase
const config = {
...
...
};
firebase.initializeApp(config);
}
startApp() {
console.log('START APP');
// Initialize Firebase here???
const tabs = [
...
];
if (this.state.loggedIn) {
Navigation.startTabBasedApp({
tabs,
tabsStyle: {
...
}
});
} else {
Navigation.startSingleScreenApp({
...
});
}
} // startApp
}
export default App;
【问题讨论】:
-
请分享您的代码的相关部分,否则很难找出确切的问题。此外,您还写了“componentWillMounth”。检查代码中是否没有相同的错字,因为如果是,那就是它没有被调用的原因。
-
嗨@martinarroyo,现在没有太多事情发生,我只是想找出初始化firebase配置的最佳位置。无论如何,我添加了一些简化的代码以使其更清晰,希望对您有所帮助。
标签: firebase react-native react-native-navigation