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

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
});
});
};
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.
The code you have included in your question contains no call to either
setState
orforceUpdate
, so your error is most likely elsewhere.– Tholle
Jul 1 at 14:27