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

198
Vistas
React.createContext throwing error when using Provider

I am trying to use React contexts to manage my states throughout child components in typescript. However, I currently face an issue with the following code:

Inside contexts/context.ts I have:

export const MyContext = React.createContext(null);

Inside components/Parent.tsx I have:

import {MyContext} from '../contexts/context';

export default function Parent() {
    const [state, setState] = React.useState([]);

    const MyContextManager = React.useContext(MyContext);

    return (
       <MyContextManager.Provider value={[state, setState]}>
          <Child />
       </MyContextManager.Provider>
    )  
 }

And inside my Child component I have:

const [state, setState] = React.useContext(MyContext);

const handleState = (value) => {
      setState(value);
}

However, I currently get an error:

TypeError: MyContextManager is null
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You meant to use MyContext.Provider. Check the documentation.

Also you mentioned using TypeScript, yet that TypeError is a runtime error. It seems like TS thinks your MyContextManager is of type any or so. That, or TypeScript thinks having null as a component type is fine.

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