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?