1 回答

TA貢獻(xiàn)1111條經(jīng)驗(yàn) 獲得超0個(gè)贊
假設(shè)該函數(shù)getFromFirebase返回一個(gè)承諾,那么您可以將方法切換為異步,如下所示:
export const getUserNotes = (currentUserId) => async (dispatch, getState) => {
// wait the result dispatched
await getFromFirebase(`/Notes/${currentUserId}/`, (response) => {
var ids = Object.keys(response)
dispatch(setNoteIds(ids)); //should dispatch ids something like this [1,2,3,4,5]
})
const test= getIds(getState());
}
或者如果這getFromFirebase不是一個(gè)承諾,你可以用一個(gè)承諾來包裝它:
export const getUserNotes = (currentUserId) => async (dispatch, getState) => {
// wrap in a promise
await new Promise(resolve => {
getFromFirebase(`/Notes/${currentUserId}/`, (response) => {
var ids = Object.keys(response)
dispatch(setNoteIds(ids)); //should dispatch ids something like this [1,2,3,4,5]
resolve();
})
})
const test= getIds(getState())
}
添加回答
舉報(bào)