Complete the code to import the React library in a functional component.
import [1] from 'react'; function MyComponent() { return <div>Hello React!</div>; }
You import the main React object using import React from 'react'; to use React features in your component.
Complete the code to declare a state variable using React hooks.
import React, { [1] } from 'react'; function Counter() { const [count, setCount] = [1](0); return <button>{count}</button>; }
The useState hook lets you add state to functional components.
Fix the error in the code to correctly use the useEffect hook for side effects.
import React, { useEffect } from 'react'; function Logger() { useEffect(() => { console.log('Component mounted'); }, [1]); return <div>Check console</div>; }
Passing an empty array [] as the second argument to useEffect runs the effect only once after the component mounts.
Fill both blanks to create a context and provide it to child components.
import React, { createContext, [1] } from 'react'; const ThemeContext = createContext('light'); function App() { return ( <ThemeContext.Provider value=[2]> <Child /> </ThemeContext.Provider> ); }
You import useContext to consume context later, and provide a value like 'dark' to the provider.
Fill all three blanks to create a memoized callback that updates state.
import React, { useState, [1], useCallback } from 'react'; function Counter() { const [count, setCount] = useState(0); const increment = useCallback(() => { setCount(count [2] 1); }, [[3]]); return <button onClick={increment}>{count}</button>; }
useMemo is imported but not needed here; the correct hook to memoize is useCallback. The increment function adds 1 to count using +, and the dependency array includes count.