React | Context API | Question 7

Last Updated :
Discuss
Comments

Given the following code, what will be rendered in the ChildComponent?

JavaScript
const LanguageContext = React.createContext("English");

const ParentComponent = () => {
    return (
        <LanguageContext.Provider value="Spanish">
            <ChildComponent />
        </LanguageContext.Provider>
    );
};

const ChildComponent = () => {
    const language = useContext(LanguageContext);
    return <p>{language}</p>;
};


English

Spanish

undefined

null

Share your thoughts in the comments