Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback come faster then setState #148

Open
vitaly87 opened this issue Jun 13, 2021 · 0 comments
Open

Callback come faster then setState #148

vitaly87 opened this issue Jun 13, 2021 · 0 comments

Comments

@vitaly87
Copy link

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);
        }
      });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant