Redux 'dispatch' 函数未被调用
Redux 'dispatch' function isn't called
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 代码的 none类型运行。相反,我得到一个错误:
"YellowBox.js:82 可能未处理的承诺拒绝 (id: 0):
错误:操作可能没有未定义的 "type" 属性。你有没有拼错一个常量?
为什么 dispatch() 不起作用?
我想你想要 import { FETCH_PRICES } from "./types";
因为我无法想象你默认导出 FETCH_PRICES。
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 代码的 none类型运行。相反,我得到一个错误:
"YellowBox.js:82 可能未处理的承诺拒绝 (id: 0): 错误:操作可能没有未定义的 "type" 属性。你有没有拼错一个常量?
为什么 dispatch() 不起作用?
我想你想要 import { FETCH_PRICES } from "./types";
因为我无法想象你默认导出 FETCH_PRICES。