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

867
Visualizações
React: TypeError: Cannot read properties of null (reading 'useContext') when trying to use react-bootstrap container

As stated in the title I am trying to create a layout component but using any react-bootstrap components seems to give me errors. In this case, using I get the error:

TypeError: Cannot read properties of null (reading 'useContext')

The code for this Layout component is below:

import React from 'react';
import { Container } from 'react-bootstrap';

export const Layout = (props) => (
    <Container>
        {props.children}
    </Container>
    )

And this is being called from App.js below:

import React, { Component } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { Layout } from './components/Layout';
import { Home } from './components/Home';

import './custom.css'

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

export default App;

Replacing the container tags with div renders as expected but any use of react-bootstrap causes the useContext error.

about 4 years ago · Santiago Gelvez
3 Respostas
Responde à pergunta

0

I think the issue is how you import it.

import Container from 'react-bootstrap/Container'
about 4 years ago · Santiago Gelvez Relatório

0

I got the same error, I fixed that by updating my bootstrap version.

about 4 years ago · Santiago Gelvez Relatório

0

Router must be above Switch:

<Router>
    <Layout>
        <Switch>
            <Route path="/" component={Home} />
        </Switch>
    </Layout>
</Router>

https://codesandbox.io/s/determined-zeh-r3vvl4

about 4 years ago · Santiago Gelvez 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