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

275
Vistas
ThemeToggle.js:10 Uncaught TypeError: Cannot destructure property 'toggleTheme' of 'this.context' as it is undefined

I am getting some kind of error. I've been trying to fix it but I still can't figure it out.

    import React, { Component, createContext } from "react";

export const ThemeContext=createContext();


class ThemeContextProvider extends Component{
    state={
        isLightTheme: true,
        light:{ syntax:"#555",ui:"#ddd", bg:"#eee"},
        dark:{syntax:"ddd",ui:"#333", bg:"#555"}
    }

    toggleTheme=()=>{this.setState({isLightTheme:!this.state.isLightTheme})}



    render(){ return(
        <ThemeContext.Provider value={{...this.state, toggleTheme:this.toggleTheme}}>
            {this.props.children}

        </ThemeContext.Provider>
    )
    
    }
}

export default ThemeContextProvider;

and

import React, { Component } from "react";
import { ThemeContext } from "./context";


class ThemeToggle extends Component{
    static contextType=ThemeContext;
    render(
        
    ) {
        const{toggleTheme}=this.context;
        return(
            <button onClick={toggleTheme}>Toggle the Theme</button>
        )

}
}
export default ThemeToggle;

ERROR: ThemeToggle.js:10 Uncaught TypeError: Cannot destructure property 'toggleTheme' of 'this.context' as it is undefined.

about 4 years ago · Juan Pablo Isaza
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