Checking if the component is mounted before perfom some animation

When we use the button to remove some element from the DOM, it throws this error message:
Uncaught Error: Invariant Violation: replaceState(...): Can only update a mounted or mounting component.

I think is because we are trying to change the state of an unmounted object.