我内有一个函数actions/index
,该函数调用一个动作创建者,该动作创建者调度一个动作,但从未被调用。我认为我在Redux中缺少一些东西。该数据库是Firebase实例。
export function handleInitialVisit() {
...
DB.child('profiles')
.child(id)
.set(data)
.then(res => handleVisit());
}
function handleVisit() {
console.log('called') // called
return (dispatch, getState) => {
console.log('called'); // never called
...
dispatch({type: SET_DB_REF, payload: visitReferencePath});
}
}
我唯一的猜测是,因为我没有使用connect或store来调用它,所以它不具有那些dispatch和getState属性。问题是,我不需要从组件中调用它。我希望在呈现组件之前发生这种情况。它试图在交互发生和呈现组件之前弄清楚用户。
您应该使用dispatch
函数来分派动作:
export function handleInitialVisit() {
...
DB.child('profiles')
.child(id)
.set(data)
.then(res => dispatch(handleVisit()));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句