3

I just created a new app,I'm starting to learn react but I'm ready to give up....just before I do want to share my code:

index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

APP.js:

import logo from './logo.svg';
import './App.css';
import Navigation from './component/Navigation';

function App() {
  return (
    <div className="App">
      <header className="App-header">
<Navigation/>        
      </header>
    </div>
  );
}

export default App;

Navigation.jsx:

import React, { Component } from 'react';
import { Navbar, Nav, NavDropdown, Container } from 'react-bootstrap';

class Navigation extends Component {

    render() {
        return (
            <Navbar collapseOnSelect expand="lg" bg="white" >
                <Container>    </NavDropdown>
                    </Nav>
                    <Nav>
                        <Nav.Link href="#deets">More deets</Nav.Link>
                        <Nav.Link eventKey={2} href="#memes">
                            Dank memes
  </Nav.Link>
                    </Nav>
                </Navbar.Collapse>
            </Container>

        </Navbar>
);
    }
}
export default Navigation;

Please let me know where is the problem,I also have seen a similar question with no answer...

PureAbap
  • 99
  • 3
  • 13

2 Answers2

0

Like @CertainPerfomance already noted, you aren't using any hooks in the code provided. Nevertheless, if you get the 'Invalid hook call' error, you're either trying to call a hook from non-functional component(or in other words - a class component) or maybe you're trying to call it in a loop/conditional statement, which breaks the rules for hook usage. Also, you might be importing React twice. Checkout this official page which should give you some additional information about the specific error.

You will most probably fix your error if you convert your components to functional ones.

EDIT: After your update, also checkout this: Invalid hook call. Hooks can only be called inside of the body of a function component.

zhulien
  • 5,145
  • 3
  • 22
  • 36
0

I think you had two instances of react running at the same time. Surprisingly this did not come to your attention until you tried using react-bootstrap. In that case, you installed react via npm while still having the react tag in my master template (obviously resulting in embedding the react code twice).

Nisharg Shah
  • 16,638
  • 10
  • 62
  • 73