Oluwasetemi / Oluwasetemi/react-note

Bug: ThemeContext missing Provider wrapper in hooks.md

Open
#46 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Vue
Stars
3
Forks
13
PR merge metrics
No merged PRs in 30d

Description

Description

In pages/hooks.md, the ThemeContext example shows context creation and consumption but is missing the ThemeProvider component that should wrap children with the context value.

Location

File: pages/hooks.md
Lines: 617-626

Current Code

import { createContext, use } from 'react'

const ThemeContext = createContext()

const ThemeConsumer = () => {
  const { theme, toggleTheme } = use(ThemeContext)

  return <button onClick={toggleTheme}>Current theme: {theme}</button>
}

Expected Code

import { createContext, use, useState } from 'react'

const ThemeContext = createContext()

const ThemeProvider = ({ children }) => {
  const [theme, setTheme] = useState('light')

  const toggleTheme = () => {
    setTheme(prev => prev === 'light' ? 'dark' : 'light')
  }

  return (
    <ThemeContext.Provider value={{ theme, toggleTheme }}>
      {children}
    </ThemeContext.Provider>
  )
}

const ThemeConsumer = () => {
  const { theme, toggleTheme } = use(ThemeContext)

  return <button onClick={toggleTheme}>Current theme: {theme}</button>
}

// Usage
function App() {
  return (
    <ThemeProvider>
      <ThemeConsumer />
    </ThemeProvider>
  )
}

Why This Matters

  • Without a Provider, calling use(ThemeContext) will return undefined and cause runtime errors
  • This is teaching material - students need to see the complete pattern of Context creation, Provider, and Consumer
  • The Provider pattern with children props is a fundamental React concept that should be demonstrated

References

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pages/hooks.md at lines 617-626 and compare the ThemeContext example with the referenced React createContext and use documentation. Complete the example with the ThemeProvider and usage shown in the issue, then verify that the teaching example provides a context value and supports toggling the theme.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.