我试图使用ES6函数返回数据,但它返回的是函数而不是结果。
根据我的代码,结果应该是正确的或错误的。
我的密码
get_gathereddata_status.js
export default () => (dispatch, getState) => {
const { experiment } = getState();
const { selectedTab, gatherData } = experiment.tabs;
const { environmentalChanges: { environmentFactor, environmentLocation } } = experiment;
const { populationChanges: { populationlLocation, populationFactor } } = experiment;
if (selectedTab === 'tab1') {
return environmentFactor !== '' && environmentLocation !== '' && !gatherData[selectedTab];
} else if (selectedTab === 'tab2') {
return populationlLocation !== '' && populationFactor !== '' && !gatherData[selectedTab];
}
return false;
};mapStateToProps
function mapStateToProps({ experiment }) {
const { selectedTab } = experiment.tabs;
const isGatherDataEnabled = gatherDataStatus();
console.log(isGatherDataEnabled);
return {
selectedTab,
isGatherDataEnabled
};
}console.log in mapStateToProps
ƒ (dispatch, getState) {
var _getState = getState(),
experiment = _getState.experiment;
var _experiment$tabs = experiment.tabs,
selectedTab = _experiment$tabs.selectedTab,发布于 2017-10-12 14:35:26
get_gathereddata_status.js返回一个返回另一个函数的函数:
() => (dispatch, getState) => { //...}所以当你用:
const isGatherDataEnabled = gatherDataStatus();
// assuming gatherDataStatus this is the same as get_gathereddata_status.jsisGatherDataEnabled现在是gatherDataStatus()返回的函数,而不是第二个函数的结果。
我认为您只想导出第二个函数:
export default (dispatch, getState) => { //.. }或者,如果确实需要,可以调用返回的函数:
console.log(isGatherDataEnabled(dispatch, getState));
// You need to call this with the expected arguments. Where do these come from?https://stackoverflow.com/questions/46712121
复制相似问题