How to logout in react

Viewed 34538

I'm trying to logout using this method: In render I have a div like this:

<div>
   <a href="#" onClick={this.logout()}>LOGOUT</a>
</div>

and the logout function:

logout() {
    // localStorage.clear();
    location.href = 'localhost:3000';
}

At localhost:3000 I have the login page.

Put when I press logout, nothing happends. What can I do? Thank you

2 Answers

this solved my problem

 logout() {
        localStorage.clear();
        window.location.href = '/';
    }
Related