Complete the code to create a context using React.
import React from 'react'; const MyContext = React.[1]();
React's createContext function is used to create a new context object.
Complete the code to provide the context value to child components.
function MyProvider({ children }) {
const value = { user: 'Alice' };
return <MyContext.[1] value={value}>{children}</MyContext.[1]>;
}The Provider component of the context is used to pass the value down to children.
Fix the error in the code to consume context inside a functional component.
import React, { [1] } from 'react'; function User() { const context = [1](MyContext); return <div>{context.user}</div>; }
The useContext hook is used to read the current context value inside a component.
Fill both blanks to create and use a context provider with a default value.
const ThemeContext = React.[1]('light'); function App() { return <ThemeContext.[2] value="dark">Content</ThemeContext.[2]>; }
Use createContext to create the context with a default value, and Provider to pass a new value.
Fill all three blanks to consume context and display its value inside a component.
import React, { [1] } from 'react'; const LanguageContext = React.createContext('English'); function DisplayLanguage() { const language = [2](LanguageContext); return <p>Current language: [3]</p>; }
Import and use useContext to get the context value, then display the variable language.