Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
error when I import useContext to another component

I am trying to import the value of useContext but I am getting this error :

  Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

What I am missing here ?

AllThemeContext.js

import React, { createContext, useState } from "react";
export const AllContext = createContext();

const AllContextProvider = (props) => {
  const submittedInput = props.submittedInput;

  return (
    <AllContext.Provider value={{ submittedInput }}>
      {props.children}
    </AllContext.Provider>
  );
};

export default AllContextProvider;

logo.js

import React from "react";
import AllContextProvider from "../context/AllThemeContext";
import "./Logo.scss";
// Component
const Logo = () => {
  return (
    <AllContextProvider.Consumer>
      {(context) => {
        console.log(context);
      }}
    </AllContextProvider.Consumer>
  );
};
export default Logo;
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You should import AllContext from AllThemeContext which is the named export and not the default export.

import React from "react";
import { AllContext } from "../context/AllThemeContext";
import "./Logo.scss";
// Component
const Logo = () => {
  return (
    <AllContext.Consumer>
      {(context) => {
        console.log(context);
      }}
    </AllContext.Consumer>
  );
};
export default Logo;
about 4 years ago · Juan Pablo Isaza Denunciar

0

Because you don't return anything in the children of AllContextProvider.Consumer.

You need add return component:

  {(context) => {
    console.log(context);
    return <div>Hello world</div>
  }}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda