When I logout of my meteor app I get memory leak error. It seems to happen about 50% of the time and I can't figure out what I'm doing wrong here. Can someone please explain what's wrong with my method.
Error message
Can't perform a React state update 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.
App details
Metoer, React, React-Router V4
Path: LogoutButton.jsx
class LogoutButton extends React.Component {
constructor(props) {
super(props);
this.state = {
logoutRedirect: false
};
this.handleLogout = this.handleLogout.bind(this);
}
handleLogout = e => {
e.preventDefault();
Meteor.logout(err => {
if (err) {
console.log('err', err);
} else {
this.setState({ logoutRedirect: true });
}
});
};
render() {
const logoutRedirect = this.state;
if (logoutRedirect.logoutRedirect) {
return <Redirect to="/" />;
}
return (
<button
type="button"
className="btn btn-link dropdown-item text-dark"
onClick={this.handleLogout}
>
<FontAwesomeIcon icon={faSignOutAlt} className="mr-2 text-dark" />
Logout
</button>
);
}
}