Complete the code to declare a state variable using React hooks.
const [count, setCount] = [1](0);
The useState hook is used to declare state variables in React functional components.
Complete the code to pass a prop named 'title' with value 'Hello' to a component.
<MyComponent [1]="Hello" />
Props are passed as attributes to components. Here, title is the prop name.
Fix the error in accessing a prop inside a functional component.
function Greeting([1]) { return <h1>{props.name}</h1>; }
The component must receive props as a parameter to access its properties.
Fill both blanks to create a state variable and update it on button click.
const [[1], [2]] = useState(0);
The first element is the state variable name, and the second is the function to update it.
Fill all three blanks to create a component that receives a prop and uses state to toggle a message.
function Message([1]) { const [[2], [3]] = useState(true); return ( <div> <h1>{show ? text : ''}</h1> <button onClick={() => setShow(!show)}>Toggle</button> </div> ); }
The component receives a prop named 'text'. The state variable 'show' controls visibility, updated by 'setShow'.