Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!