Reputation: 91
I'm doing a React + Electron application and I'm getting this error:
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: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app
But my class is already a function component (I used this post as reference Invalid hook call. Hooks can only be called inside of the body of a function component):
import React, {useState} from 'react'
import { HashRouter, Route, Link } from 'react-router-dom';
import { AppBar } from '@material-ui/core';
import Login from './loginView/Login.jsx';
import vendaView from './vendaView/TelaDeVenda.jsx';
import relatorioView from './relatorioView/Relatorio.jsx';
import estoqueView from './estoqueView/Estoque.jsx';
import configuracoesView from './configuracoesView/Configuracoes.jsx'
import cargosView from './cargosView/Cargos.jsx';
import historicoView from './historicoView/HistoricoDeVendas.jsx';
const Index = () => {
const [esta_logado, setLogado] = useState(0);
const [usuario, setUsuario] = useState({});
function liberarLogin(usuario) {
setLogado(1);
setUsuario(usuario)
}
function deslogar(usuario) {
setLogado(0);
setUsuario(usuario)
}
return (
<div>
{
!esta_logado ?
(<Login liberarLogin = {liberarLogin} />) :
(<AppBar position="static">
<HashRouter>
<Link to={'/vendaView'}>Caixa</Link> <br/>
<Link to={'/relatorioView'}>Relatorio</Link> <br/>
<Link to={'/estoqueView'}>Estoque</Link> <br/>
<Link to={'/configuracoesView'}>Configuracoes</Link> <br/>
<Link to={'/cargosView'}>Cargos</Link> <br/>
<Link to={'/historicoView'}>Histórico de Vendas</Link> <br/>
<button onClick={deslogar}>Sair</button>
<hr></hr>
<Route path='/vendaView' component={vendaView}/>
<Route path='/relatorioView' component={relatorioView}/>
<Route path='/estoqueView' component={estoqueView}/>
<Route path='/configuracoesView' component={configuracoesView}/>
<Route path='/cargosView' component={cargosView}/>
<Route path='/historicoView' component={historicoView}/>
</HashRouter>
</AppBar>)
}
</div>
)
};
export default Index;
When I delete <AppBar position="static">
and </AppBar>
the error stops...
What am I doing wrong?
ERROR MESSAGE
Upvotes: 2
Views: 5716
Reputation: 91
Solved!
I change the signature from const Index = () =>
to export default function Index()
and delete export default Index;
That was enought!
Upvotes: 0