Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function Header(props) {
...
function renderLogout() {
if(props.location.pathname === '/home'){
return(
<div className="ml-auto">
<button className="btn btn-danger" onClick={() => handleLogout()}>Logout</button>
</div>
)
}
}
function handleLogout() {
localStorage.removeItem(ACCESS_TOKEN_NAME)
props.history.push('/login')
}
return(
<nav className="navbar navbar-dark bg-primary">
<div className="row col-12 d-flex justify-content-center text-white">
<span className="h3">{props.title || title}</span>
{renderLogout()}
</div>
</nav>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment