Redux' dispatch'函数不被称为

时间:2018-03-05 18:54:06

标签: javascript reactjs redux redux-thunk

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('已发送')从不这样做,并且没有我的减少代码用于" FETCH_PRICES"类型运行。相反,我得到一个错误:

" YellowBox.js:82可能未处理的承诺拒绝(id:0): 错误:操作可能没有未定义的"类型"属性。你拼错了吗?"

为什么dispatch()不起作用?

1 个答案:

答案 0 :(得分:0)

我想你想要import { FETCH_PRICES } from "./types";,因为我无法想象您将FETCH_PRICES导出为默认值。