Skip to content

Instantly share code, notes, and snippets.

@mentix02
Last active December 2, 2020 12:10
Show Gist options
  • Save mentix02/75fdd140bd988d28d0ecb3862122c648 to your computer and use it in GitHub Desktop.
Save mentix02/75fdd140bd988d28d0ecb3862122c648 to your computer and use it in GitHub Desktop.
a {
color: blue;
}
.link {
color: blue;
cursor: pointer;
text-decoration: underline;
}
.active {
color: orange;
}
import React from "react";
import "./styles/Navigation.css";
import { useDispatch } from "react-redux";
import { NavLink } from "react-router-dom";
import { logOut } from "../store/auth/actions";
import { useAuthenticated } from "../store/auth/hooks";
function Navigation() {
const dispatch = useDispatch();
const isAuthenticated = useAuthenticated();
return (
<ul>
<li>
<NavLink activeClassName="active" exact to="/">
Home
</NavLink>
</li>
{isAuthenticated ? (
<>
<li>
<NavLink activeClassName="active" to="/account">
Account
</NavLink>
</li>
<li>
<span className="link" onClick={() => dispatch(logOut())}>
Logout
</span>
</li>
</>
) : (
<li>
<NavLink activeClassName="active" to="login">
Sign In
</NavLink>
</li>
)}
</ul>
);
}
export default Navigation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment