If your asynchronous code tries to set the state of a component that has been unmounted, nothing will happen. A warning will be logged, and the state won't be set. It's actually very important that this warning is logged; otherwise, you would have a hard time trying to solve subtle race condition bugs.
The correct approach is to create cancellable asynchronous actions. Here's a modified version of the users() API function that you implemented in the fetching component data example:
import { Promise } from "bluebird";
Promise.config({ cancellation: true });
export function users(fail) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (fail) {
reject(fail);
} else {
resolve({
users: [
{ id: 0, name: "First" },
{ id: 1, name: "Second" },
{ id: 2, name: "Third" }
]
});
}
}, 4000);
});
}
Instead...