Complete the code to create a new context using React Native's Context API.
import React from 'react'; const MyContext = React.[1]();
We use createContext() to create a new context object.
Complete the code to provide a context value to child components.
import React from 'react'; const MyContext = React.createContext(); export default function App() { return ( <MyContext.[1] value={{ name: 'Alice' }}> <ChildComponent /> </MyContext.[1]> ); }
The Provider component supplies the context value to its children.
Fix the error in the code to consume context inside a functional component.
import React, { [1] } from 'react'; const MyContext = React.createContext(); function ChildComponent() { const context = [1](MyContext); return <Text>{context.name}</Text>; }
We use the useContext hook to access context values inside functional components.
Fill both blanks to create a context and provide a default value.
const MyContext = React.[1]([2]);
createContext can take a default value used when no Provider is present.
Fill all three blanks to consume context and display a property safely.
import React, { [1] } from 'react'; const MyContext = React.createContext(); function Display() { const context = [2](MyContext); return <Text>{context?.[3] ?? 'No name'}</Text>; }
Import and use useContext to get context, then access the name property safely with optional chaining.
