我正在使用redux和ES6在react.js中工作。我有一个行动文件导出的函数,像这样:为什么我的函数在ES6中被导入为值'0'?
MonthlyRevenueActions.js
export function fetchMonthlyRevenue(name, startDate, endDate) {
return function(dispatch) {
dispatch(console.log("name": " + name + ", start: " + startDate + ", end: " + endDate));
}
}
然后在我的容器代码,我有一个import语句,并尝试使用该功能,但我可以在Chrome DevTools看到变量的值是0:
MonthlyDisplayContainer.js:
import {otherFunc, fetchMonthlyRevenue, otherFunctionTwo} from 'actions/monthly/MonthlyRevenueActions'
const mapStateToProps = (state, ownProps) => {
//... other code that's being executed
fetchMonthlyRevenue(name, startDate, endDate);
}
我可以看到值name
,startDate
和endDate
,但fetchMonthlyRevenue()
功能仅仅是0
我期待我在思考范围时遗漏了一些东西(我是ES6的新手),但是对于我的生活却无法弄清楚如何执行这个功能。
在此先感谢您的帮助。
我不了解这一行代码。你正在执行一个函数,它返回一个函数,并且对返回值无所作为?是的0是奇怪的,但是......代码也是如此...... –
你得到的错误是什么? – searsaw
它没有给出错误...它是代码运行通过,没有任何错误。如果我把一个'console.log()'放在它的'fetchMonthlyRevenue()'行旁边打印出来。 – Cuga