I have a redux saga API, where by I am connecting to firebase and reading records of data.
var roomRef = firebase.database().ref('/Users/' + userid + '/rooms')
var rooms = []
roomRef.once('value', function (snap) {
var roomkeys = snap.val()
for (var roomkey in roomkeys) {
firebase.database().ref('/Rooms/' + roomkey).once('value', function (item) {
rooms.push(item.val())
})
}
console.log(rooms)
--> put({type: 'LOAD_ROOMS', payload: { rooms: rooms}})
})
Since my put is inside a callback function I cannot use the yield keyword. How do I dispatch an event to change the state of my reducer with the new values 'rooms'
once
method already returns a Promise. If you have a function like:function getRooms(userId){ return firebase.database().ref('users/' + userId + '/rooms').once('value').then( snap => snap.val() ) }
, you can thenconst rooms = yield call(getRooms, userId)
– Kimberykimble