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

154
Views
How to properly use useContext whit styled-components

I'm implementing a dark mode, but I did not get how to use theme inside my GlobalStyle, I'm trying to implement this since 4 days ago, I watched countless videos. I'm stuck at this error at the moment:

Uncaught ReferenceError: theme is not defined
    GlobalStyle GlobalStyle.jsx:7

GlobalStyle.jsx

import { createGlobalStyle } from "styled-components";

export const GlobalStyle = createGlobalStyle`
body{
    margin:0;
    padding:0;
    background-color: ${props => theme.colors.primary}; // error HERE !!!
    color: ${props => theme.colors.text};
}
`;

App.jsx

import { useContext } from "react"
import { ThemeLocalContext, ThemeLocalProvider } from "./context/themeContext"
import { ThemeProvider } from "styled-components"
import {Paths} from "./pages/Paths/"
import { GlobalStyle } from "./styles/GlobalStyle/GlobalStyle"

function App() {

  const theme = useContext(ThemeLocalContext);
  console.log(theme) // this print my theme object
  return (
    
    <div>
      <ThemeLocalProvider>
        <>
        <ThemeProvider theme={theme}>
        <GlobalStyle/>
        <Paths/>
        </ThemeProvider>
        </>
      </ThemeLocalProvider>
    </div>
  )
}

export default App

ThemeContext.jsx

import React, { createContext, useState } from "react";
import { lightTheme } from "../styles/Theme/lightTheme";
import { darkTheme } from "../styles/Theme/darkTheme";


export const ThemeLocalContext = createContext(lightTheme);

export const ThemeLocalProvider = ({children}) => {
    const [theme, setTheme] = useState(lightTheme);

    const handleChange = (theme) => {
        setTheme(theme.title === 'light' ? darkTheme : lightTheme);
    }

    return (
        <ThemeLocalContext.Provider value={theme}>
            {children}
        </ThemeLocalContext.Provider>
    )
}
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!