javascript - 使用 Expo AppLoading 从 firebase 预加载数据
问题描述
在应用程序进入主页之前,我正在尝试使用 Expo 上的 AppLoading 从 firebase 预加载数据。我不断收到错误消息。
“错误:找不到 react-redux 上下文值;请确保组件包装在 <Provider> 中”
import React, { useState } from "react";
import { createStore, combineReducers, applyMiddleware } from "redux";
import { Provider } from "react-redux";
import ReduxThunk from "redux-thunk";
import productsReducer from "./store/productReducer";
import createdProducts from "./store/createdProductReducer";
import storeName from "./store/StoreNameReducer";
import authReducer from "./store/authReducer";
import { useDispatch } from "react-redux";
import * as ProdActions from "./store/productActions";
import AppLoading from "expo-app-loading";
import InventoryNavigator from "./navigation/InventoryNavigator";
const rootReducer = combineReducers({
products: productsReducer,
availableProducts: createdProducts,
auth: authReducer,
storeName: storeName,
});
const store = createStore(rootReducer, applyMiddleware(ReduxThunk));
export default function App() {
const [fireBLoaded, setFireBLoaded] = useState(false);
const dispatch = useDispatch();
const fetchFirebase = () => {
dispatch(ProdActions.fetchAvailableProducts());
dispatch(ProdActions.fetchStoreName());
dispatch(ProdActions.fetchProducts());
};
if (!fireBLoaded) {
return (
<AppLoading
startAsync={fetchFirebase}
onFinish={() => setFireBLoaded(true)}
onError={console.warn}
/>
);
} else {
return (
<Provider store={store}>
<InventoryNavigator />
</Provider>
);
}
}
我尝试过的:
const fetchFirebase = async () => {
任何帮助将不胜感激,我对 React Native 还是新手。
解决方案
你的fetchFirebase
功能应该是async
像这样 -
const fetchFirebase = async () => {
// Perform Aysnc operations here...
dispatch(ProdActions.fetchAvailableProducts());
dispatch(ProdActions.fetchStoreName());
dispatch(ProdActions.fetchProducts());
};
我在这里没有看到任何其他错误除了这个
推荐阅读
- python - 我试图运行一个 python 脚本,但得到 ImportError:尝试相对导入,没有已知的父包
- loops - 已收到符文,但未从 chan 收到 struct
- javascript - REACTJS:我如何在一个 Web 应用程序上拥有多个用户?
- swift - 如何使 mapView 和 segmentedControl 相对于 AdMob 自适应横幅移动
- spring-boot - Spring webclient POST方法 - 错误处理
- bash - macOS 11.2.3 bashrc 没有重新识别常见标志
- python-3.x - 在 jupyter notebook 中循环传入类似终端的命令的值
- vb.net - vb.net + Oxyplot,数据来自数据表
- prolog - Prolog - 1 和 0.5 之间的比较失败
- go - 无需阅读即可确定 Golang Gzip 文件的长度?