Question from the React ⚛️ test

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

Medium

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 612 times
Edit
5
Community Evaluations
developer avatar
Yossra
06/04/2023
le bouton ne s'affiche pas je crois que c'est la bonne réponse car il manque l'élément export au niveau de la ligne 11 exprt function App() {
developer avatar
Nazar
11/09/2023
We cannot pass property 'theme' to the button component.
developer avatar
Vincent Cotro
07/11/2023
I updated the question.