Topic: Getting invalid hook call error in React when I used materidal design bootstrap component in my application
saumitravishal1991 free asked 3 years ago
Expected behavior I should see header option at top of my page
Actual behavior I am getting below invalid hook call error in React when I used materidal design bootstrap component in my application
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app Resources (screenshots, code snippets etc.) Header.js
import React, { useState } from "react"; import { MDBNavbar, MDBNavbarBrand, MDBNavbarNav, MDBNavItem, MDBNavLink, MDBNavbarToggler, MDBCollapse, MDBFormInline, MDBDropdown, MDBDropdownToggle, MDBDropdownMenu, MDBDropdownItem, } from "mdbreact";
const Header = () => { return ( <> Navbar Home Features Pricing Dropdown Action Another Action Something else here Something else here ); };
export default Header;
App.js import logo from './logo.svg'; import './App.css'; import Header from './components/Header';
function App() { return ( ); }
export default App;
index.js import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; import '@fortawesome/fontawesome-free/css/all.min.css'; import'bootstrap-css-only/css/bootstrap.min.css'; import'mdbreact/dist/css/mdb.css'; import reportWebVitals from './reportWebVitals';
ReactDOM.render( , document.getElementById('root') );
reportWebVitals();
Krzysztof Wilk staff answered 3 years ago
Hi!
The problem probably occurs due to the third statement in the error. To fix that you can try to run npm dedupe
to remove additional copies of the React recursively.
If that won't work - you can remove the node_modules
folder and package-lock.json
(or yarn.lock)
file, remove react
and react-dom
from your dependencies in the package.json
(it will be installed with our mdbreact package) and run npm install
once again. :)
Keep coding!
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Free
- Premium support: No
- Technology: MDB React
- MDB Version: MDB4 5.0.1
- Device: Laptop
- Browser: Google
- OS: Window 10
- Provided sample code: No
- Provided link: No