firebaseui-web-react icon indicating copy to clipboard operation
firebaseui-web-react copied to clipboard

Callback come faster then setState

Open vitaly87 opened this issue 3 years ago • 0 comments

Hi all, I am trying to setState the value of callback on data change, The issue that the callback is faster then my setState , that making the prev state to update not correct values, What can be done?

 commentsRef.on("child_changed", (data) => {
     
        if (guests) {
          const key = data.key;
          const updatedGuest = data.val();
//guests ->isnt updated from last trigger
          const cloneGuests =_.cloneDeep(guests);
          cloneGuests.forEach((element, index) => {
            if (element.guestID === key) {
              cloneGuests[index] = updatedGuest;
            }
          });
          setGuests(cloneGuests);
        }
      });

vitaly87 avatar Jun 13 '21 11:06 vitaly87