Answer the question
In order to leave comments, you need to log in
How to call dispatch from a generator function inside an event subscription from firebase?
There are two options for the function.
In this - yield cannot be called where I want
function* subscribeToChatChanges () {
firebase
.database()
.ref('chats')
.on('child_added', (snapshot) => {
yield put({ type: ADD_CHAT_TO_STORE, payload: {chatId: snapshot.key, value: snapshot.val()} })
})
}
function* subscribeToChatChanges () {
var chat = yield call(() => {
return new Promise((resolve, reject) => {
firebase
.database()
.ref('chats')
.on('child_added', (snapshot) => {
var chat = {id: snapshot.key, name: snapshot.val(), messageList:[]}
resolve(chat)
})
})
})
yield put({ type: ADD_CHAT_TO_STORE, payload: chat })
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question