useContext() is undefined when i use useLocation()

Im working on a website using Gatsby and React.
Im 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);

  const location = useLocation();

  return (
      a page

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

Source: React – Stack Overflow

November 30, 2021
Category : News
Tags: gatsby | javascript | reactjs | runtime-error | use-context

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.