Complete the code to create a state variable using React hooks.
const [count, setCount] = [1](0);
The useState hook creates a state variable and a function to update it.
Complete the code to pass state as a prop from a parent to a child component.
<ChildComponent [1]={count} />Props are named attributes. Here, the prop name is count to pass the state value.
Fix the error in the child component to correctly receive props.
function ChildComponent([1]) { return <p>{count}</p>; }
props which would require props.count inside the component.To correctly access the count prop in the child component, destructure it from the props object using ({count}) in the function parameters.
Fill both blanks to create a context and provide it to child components.
const MyContext = React.[1](); function App() { const [value, setValue] = React.useState(0); return ( <MyContext.[2] value={{ count: value }}> <ChildComponent /> </MyContext.[2]> ); }
createContext creates a context object. The Provider component supplies the context value to children.
Fill all three blanks to consume context value inside a child component.
function ChildComponent() {
const value = React.[1](MyContext);
return <p>Value: {value.[2]</p>;
}
// Context value is an object like { count: 5 }
// Access the count property with [3]useContext hook reads the context value. The value is an object, so access the count property to display it.