0
votes

I am new to firebase. I want to get realtime data when a user click on any pushKey. When i click on another node i get previous node data also.I dont know where to use ref.off('value',listener). please help me out. Anyhelp will be appreciated

export const fetchCurrentCircleLocation = pushKey => { return async dispatch => {

let ref = firebase.database().ref(Circles/${pushKey}/members);

let listener = await ref.on("value", snapshot => {
  // console.log("circleLocation", snapshot.val());
  dispatch({
    type: FETCH_CURRENT_GROUP_CIRCLE_LOCATION,
    payload: snapshot.val()
  });
});

}; };

1

1 Answers

0
votes

Try using once. It will go through your database items only once. You don't need to remove listener.

ref.once("value", function (snapshot) {
        snapshot.forEach((child) => {
            console.log(child.val())

        });
    });