index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from "react";
  2. import { Link, withRouter } from "react-router-dom";
  3. import { connect } from "react-redux";
  4. const liArr = [
  5. { path: "/", id: 1, text: "Main", hideWhenAuth: false },
  6. { path: "/count", id: 2, text: "Counter from redux", hideWhenAuth: false },
  7. { path: "/redux-todo", id: 3, text: "Todo redux", hideWhenAuth: false },
  8. { path: "/form", id: 4, text: "TODO REDUX_FORM", hideWhenAuth: false },
  9. { path: "/auth", id: 5, text: "Auth", hideWhenAuth: true }
  10. ];
  11. const header = props => {
  12. const event = () =>
  13. new Promise((resolve, reject) => {
  14. setTimeout(() => {
  15. props.history.push("/test");
  16. }, 5000);
  17. });
  18. return (
  19. <header className="header" id="header">
  20. <div className="header__left-wrapper">
  21. <div className="header__logo-box">logo</div>
  22. <nav className="header__nav">
  23. <ul className="header__list">
  24. {liArr.map(el =>
  25. el.hideWhenAuth && props.user ? null : (
  26. <li className="header__item" key={el.id}>
  27. <Link to={el.path}>{el.text}</Link>
  28. </li>
  29. )
  30. )}
  31. </ul>
  32. </nav>
  33. <button onClick={event}>Click and wait 5s</button>
  34. </div>
  35. </header>
  36. );
  37. };
  38. const mapStateToProps = state => ({
  39. user: state.auth.user
  40. });
  41. export default connect(mapStateToProps)(withRouter(header));