I'm trying to set state after a function has finished and I'm getting the error:
Uncaught Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
I'm calling setstate in a callback after the function has finished so I thought this would work ok from what I've read, but I can't seem to make it work.
Running the function addStuff when component updates
componentDidUpdate() {
this.addStuff(() => this.setState({"loading":false}))
}
Setting a callback when complete
addStuff(callback) {
...Does a bunch of stuff
callback();
}
Can anyone suggest what I may be doing wrong here? Thanks.