Question from the React ⚛️ test

Use the `useContext` hook to render a button with a dark theme.

Easy

What is the outcome of executing the following React code (using the useContext hook)?

import React, { createContext, useContext } from 'react';
import MyCustomButton from 'somewhere';

const ThemeContext = createContext('light');

function ThemedButton() {
  const theme = useContext(ThemeContext);
  return <MyCustomButton theme={theme}>Theme: {theme}</MyCustomButton>;
}

function App() {
  return (
    <ThemeContext.Provider value='dark'>
      <ThemedButton />
    </ThemeContext.Provider>
  );
}
Author: Vincent CotroStatus: PublishedQuestion passed 1291 times
Edit
6
Community EvaluationsNo one has reviewed this question yet, be the first!