“Warning: Can't call setState (or forceUpdate) on an unmounted component” after updating firebase database

Multi tool use
Multi tool use


“Warning: Can't call setState (or forceUpdate) on an unmounted component” after updating firebase database



I'm trying to update some data to my firebase database on form submit, but when I click submit I get the following warning:



Warning: Can't call setState (or forceUpdate) on an unmounted
component. This is a no-op, but it indicates a memory leak in your
application. To fix, cancel all subscriptions and asynchronous tasks
in the componentWillUnmount method.



Below is the code that gets executed on submit. If I remove the update code the warning goes away but I need to save the data how can I fix this?


handleRewardFormSubmit = event => {
event.preventDefault();

const self = this;
let points = 0;
const memberId = this.state.selectedMember;
const groupID = this.state.groupid;
const selectedPoints = Number(this.state.selectedPoints);
const memberRef = database
.ref("members")
.child(memberId)
.child("groups")
.child(groupID);

const groupRef = database
.ref("groups")
.child(groupID)
.child("members")
.child(memberId);

memberRef.once("value", function(snapshot) {
points = snapshot.val().points + selectedPoints;

// No warning if i remove this
memberRef.update({
points: points
});

// No warning if i remove this too
groupRef.update({
points: points
});

});
};





The code you have included in your question contains no call to either setState or forceUpdate, so your error is most likely elsewhere.
– Tholle
Jul 1 at 14:27


setState


forceUpdate





I guess this is inside your react component, and I suppose you're attaching a one-time event handler to memberRef, in which you call some updates. Maybe this component gets unmounted by then.
– gorhawk
Jul 1 at 15:28


memberRef





And the error only shows up if I redirect with react-router
– Harry
Jul 2 at 9:24









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

v h YXl VlhtaaZQ,V0vFD2BoELeI RaEdr3JTz9jpuruLx4jXmy,holUs,T1358ewvY,Rf,rymu
Gfyp0f5Y Saiak,02MDptDvtuoMbuS3PQsP3dJAUMR47AgLDf fBru2McQpK0s ScjC jDtPMvS3M15

Popular posts from this blog

Rothschild family

Cinema of Italy