Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Fatal error on creating a Hamburguer-menu.

Matheus Ribeiro free asked 5 years ago


Expected behavior:

It was expeceted to show the example menu

Actual behavior:

Crashes application on load

import React, { Component } from "react";
import styled from "styled-components";
import { Nav } from "react-bootstrap";
import { NavLink } from "react-router-dom";
import "./Menu.css";
import { connect } from "react-redux";

import {
  MDBNavbar,
  MDBContainer,
  MDBNavLink,
  MDBNavItem,
  MDBHamburgerToggler,
  MDBNavbarBrand,
  MDBNavbarNav,
  MDBCollapse
} from "mdbreact";
import { BrowserRouter as Router } from "react-router-dom";

class Menu extends Component {
  state = {
    collapse1: ""
  };

  toggleSingleCollapse = collapseId => () => {
    this.setState({
      [collapseId]: !this.state[collapseId]
    });
  };

  render() {
    const NavMenu = styled(Nav)`
      height: 100%;
      width: 160px;
      position: fixed;
      z-index: 1;
      top: 110px;
      left: 10px;
      background-color: #fff;
      overflow-x: hidden;
    `;

    return (
      <Router>
        <MDBContainer>
          <MDBNavbar color="indigo darken-2" style={{ marginTop: "20px" }} dark>
            <MDBContainer>
              <MDBNavbarBrand className="white-text">MDBNavbar</MDBNavbarBrand>
              <MDBHamburgerToggler
                onClick={this.toggleSingleCollapse("collapse3")}
                id="hamburger3"
              />
              <MDBCollapse isOpen={this.state.collapse3} navbar>
                <MDBNavbarNav left>
                  <MDBNavItem active>
                    <MDBNavLink to="#!">Home</MDBNavLink>
                  </MDBNavItem>
                  <MDBNavItem>
                    <MDBNavLink to="#!">Link</MDBNavLink>
                  </MDBNavItem>
                  <MDBNavItem>
                    <MDBNavLink to="#!">Profile</MDBNavLink>
                  </MDBNavItem>
                </MDBNavbarNav>
              </MDBCollapse>
            </MDBContainer>
          </MDBNavbar>
        </MDBContainer>
      </Router>
    );
  }
}

const mapStateToProps = state => ({
  isPermissaoCOREC: state.authentication.isPermissaoCOREC,
  isPermissaoADM: state.authentication.isPermissaoADM
});

export default connect(mapStateToProps)(Menu);

Errors

TypeError: Object(...) is not a function
NavLink
node_modules/mdbreact/dist/mdbreact.esm.js:5677
  5674 | };
  5675 | 
  5676 | var NavLink = function NavLink(props) {
> 5677 |   var _useState = useState({}),
  5678 |       _useState2 = _slicedToArray(_useState, 2),
  5679 |       cursorPos = _useState2[0],
  5680 |       setCursorPos = _useState2[1];

and many other errors, but I think this one is the principal


Jakub Chmura staff answered 5 years ago


Hi @Matheus Ribeiro,

First of all, you import NavLink from `react-router-home 'and then use MDBNavLink,

You do the same with the NavMenu style according to the styled-components and you never use it.

I'm testing your example, and when I remove extra lines of code, everything works, so it seems to be a problem with your code. I can't reproduce your error, but I got others, except that none of them concerned mdbreact. I think the problem could be using mdbreact and react-bootstrap in one component, and using MDBNavbar together with Nav.

Best regards,

Kuba



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: 4.21.1
  • Device: Desktop
  • Browser: Opera 64.0.3417.73
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No