Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
Invalid hook call, from Reactjs to Nextjs

I have been a while outside the ReactJS world, and I decided to come back and give a try with NextJS. However I am getting a Invalid Hook Call issue.

I'm trying to convert my ReactJS project to a NextJS project. I'll show the code in a shorter format, just for the example.

Here is my Reactjs:

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

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

App.js

import React, {Component} from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';

import MainPage from './components/MainPage';


class App extends Component {
  render() {
    return (
        <Router>
          <main>
            <Switch>
              <Route exact path='/' component={MainPage}/>
            </Switch>
          </main>
        </Router>
    );
  }
}

export default App;

MainPage.js

import React, { Fragment } from 'react';

import './MainPage.css';

const MainPage = () => {
    return (
        <Fragment>
            <div>
                  Hello There :-)
            </div>
       <Fragment>
    );
};

export default MainPage;

Here is my Nextjs:

_app.js

import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

export default MyApp

index.js

import React, {Component} from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';

import MainPage from './components/MainPage';


class App extends Component {
  render() { **// not sure about the render**
    return (
        <Router>
          <main>
            <Switch> **// I think was switched to Routes**
              <Route exact path='/' component={MainPage}/> **// I think was switched to element**
            </Switch>
          </main>
        </Router>
    );
  }
}

export default App;

MainPage.js

import styles from '../styles/Home.module.css'

export default function Home() {
  return (
    <div className={styles.container}>    
      <main className={styles.main}>
        <h1 className={styles.title}>
          Welcome to <a href="https://nextjs.org">Next.js!</a>
        </h1>
      </main>
    </div>
  )
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you don't need react router inside next js because it has a pages folder that whatever folder you create there will be your route for example if you create an about folder and an index.js inside of it the index.js file will be shown to you on /about route;

for homepage you can create a components folder near pages folder and move your MainPage.js there and then import it in your index.js inside your pages folder;

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda