Complete the code to create a React context with a default value.
import React from 'react'; const MyContext = React.[1]('default');
The createContext function creates a new context object with a default value.
Complete the code to provide the context value to child components.
import React from 'react'; const MyContext = React.createContext('default'); export default function MyProvider({ children }) { return ( <MyContext.[1] value="provided"> {children} </MyContext.[1]> ); }
The Provider component supplies the context value to its children.
Fix the error in the code to consume the context value inside a client component.
"use client"; import React, { [1] } from 'react'; import { MyContext } from './MyProvider'; export default function MyComponent() { const value = [1](MyContext); return <div>{value}</div>; }
The useContext hook is used to read the current context value inside a client component.
Fill both blanks to create and use a context with a default number value.
import React from 'react'; const NumberContext = React.[1](0); export function NumberProvider({ children }) { return <NumberContext.[2] value={42}>{children}</NumberContext.[2]>; }
Use createContext to create the context and Provider to supply the value.
Fill all three blanks to consume a context value and display it in a client component.
"use client"; import React, { [1] } from 'react'; import { NumberContext } from './NumberProvider'; export default function ShowNumber() { const number = [2](NumberContext); return <p>The number is: [3]</p>; }
Use useContext to get the context value, then display the variable holding it.