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

288
Visualizações
useContext() is undefined when i use useLocation()

I'm working on a website using React. I'm getting this error when using useContext() and useLocation().

import React, { useContext } from "react";
import Layout from "../components/Layout";
import { LangStateContext } from "../context/LangContext";

import { useLocation } from 'react-router';


const PricingPage = () => {
  const { isIndoSelected } = useContext(LangStateContext);
  console.log(isIndoSelected);

  const location = useLocation();


  return (
    <Layout>
      a page
    </Layout>
  );
};

export default PricingPage;

This is the error im getting when i land on the page

useContext is undefined error

Can anyone explain to me why this wont work and what a good workaround would be?

Thanks you

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

useContext needs Providers to work, so make sure that you have instantiated one that has this component as a direct or indirect child.

Also make sure that the context that you have created to instantiate this provider has this isIndoSelected that you're trying to access.

You can read more about React's Context usage here.

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