0

I have written the following code to remove a node from the current branch and add it to a different branch. But it only removes the node from the current branch without adding it to the new one.

export const unregister = id => {
  return (dispatch, getState) => {
    registeredUsersRef.child(id).on("value", snapshot => {
      unregisteredUsersRef.child(id).set(snapshot.val()).then(()=> {
        registredUsersRef.child(id).remove();
      });
    });
  };
};

What can I do to set the data in a new branch before removing?

Edit: It seems that data is set to the unregisteredUsers branch but it is removed as soon as the data is removed from the registeredUsers. What can I do to avoid it?

JayaniH
  • 293
  • 1
  • 2
  • 9
  • So you're saying that `unregisteredUsersRef.child(id).set(snapshot.val())` doesn't work? Could you go into more detail about what you're trying to do, and how you're observing that the code doesn't work the way you expect? – Doug Stevenson Oct 07 '19 at 18:05
  • With the code I have written, i observed in the firebase console that the child from registeredUsers is removed but it is not set as a new child of unregisteredUsers. I want the child to be added to unregisteredUsers and then remove it from registeredUsers. – JayaniH Oct 07 '19 at 18:22
  • If the `remove()` runs, that means the `unregisteredUsersRef...set()` must have completed successfully. Are you sure `unregisteredUsersRef` points to the path you're looking at? – Frank van Puffelen Oct 07 '19 at 18:49
  • It seems that data is set to the unregisteredUsers branch but it is removed as soon as the data is removed from the registeredUsers. – JayaniH Oct 07 '19 at 19:11
  • This doesn't seem to be a complete example. Where are registeredUsersRef and unregisteredUsersRef created? Can you provide a [Minimal, Reproducable Example](https://stackoverflow.com/help/minimal-reproducible-example) ? – robsiemb Oct 07 '19 at 21:54

0 Answers0