Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Callback come faster then setState

Open
#148 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
firebase, javascript, react
Domain
frontend

Research direction

No file or test is named. Start with the commentsRef.on("child_changed") callback and the setGuests call shown in the issue, then trace how guests is captured across repeated callbacks. Done means successive child_changed events retain earlier updates and guests reflects each changed guest.

Written by the indexing model from the issue text.

Description

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);
        }
      });
Dominant language
JavaScript
Stars
1.3k
Forks
246
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/firebaseui-web-react

All issues in firebase/firebaseui-web-react

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.