HardHooks & Closures💻 Output Question

useContext Hook with Nested Components

💡

Hint

Look into how the context is being updated and how it is being accessed in each component. Make sure to use the correct methods to update and access the context.

What does this output?

const context = { theme: 'dark' }

function useTheme() { return context.theme }

function Grandparent() { console.log('Grandparent theme:', useTheme())
  return <Parent /> }

function Parent() { console.log('Parent theme:', useTheme())
  return <Child /> }

function Child() { context.theme = 'light'; console.log('Child theme:', useTheme())
  return 'Child' }

function App() { console.log('App theme:', useTheme())
  return <Grandparent /> }

console.log('Initial theme:', useTheme())
App()

Correct Output

Initial theme: dark
App theme: dark
Grandparent theme: dark
Parent theme: dark
Child theme: dark

Why this output?

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz