【发布时间】:2018-08-13 12:38:18
【问题描述】:
import firebase from "firebase";
import "firebase/firestore";
import moment from "moment";
import firebaseApp from "../firestoreConfig";
import { config } from "../../App";
import FETCH_PRICES from "./types";
const firestore = firebaseApp.firestore();
export const getPrices = () => {
return dispatch => {
let prices;
firestore
.collection("settings-daily-market")
.orderBy("MarketDate", "desc")
.limit(1)
.get()
.then(snapshot => {
snapshot.forEach(doc => {
const Pd = doc.data().PdMarket;
const Pt = doc.data().PtMarket;
const Rh = doc.data().RhMarket;
prices = { Pd, Pt, Rh };
console.log(prices);
});
dispatch({ type: FETCH_PRICES, payload: prices });
console.log("dispatched");
});
};
};
带有价格的console.log 运行,但第二个console.log('dispatched') 从不运行,并且我的“FETCH_PRICES”类型的reducer 代码没有运行。相反,我得到一个错误:
"YellowBox.js:82 可能的未处理承诺拒绝 (id: 0): 错误:操作可能没有未定义的“类型”属性。你有没有拼错一个常数?”
为什么 dispatch() 不起作用?
【问题讨论】:
-
看起来
FETCH_PRICES没有类型属性。你能发帖./types吗? -
调用dispatch之前
FETCH_PRICES的值是多少? -
谢谢大家!我错误地导入了 FETCH_PRICES。
标签: javascript reactjs redux redux-thunk