Complete the code to create a React functional component that returns a simple greeting.
function Greeting() {
return <h1>[1]</h1>;
}In JSX, text content is placed directly between the opening and closing tags without quotes. Quotes would render as visible quotes in the output.
Complete the code to import React's useState hook.
import React, { [1] } from 'react';
The useState hook is used to add state to functional components in React.
Fix the error in the React component by completing the return statement correctly.
function Welcome() {
return [1];
}React components must return JSX elements, which look like HTML tags. Returning just a string without JSX tags causes an error.
Fill both blanks to create a React component that uses useState to toggle text on button click.
import React, { [1] } from 'react'; function Toggle() { const [isOn, setIsOn] = [2](false); return ( <button onClick={() => setIsOn(!isOn)}> {isOn ? 'ON' : 'OFF'} </button> ); }
To use state in React, import useState and call it as a function to get the state and setter. Both blanks are filled with 'useState'.
Fill all three blanks to create a React component that displays a list of items using map.
function ItemList({ items }) {
return (
<ul>
{items.[1](item => (
<li key={item.[2]>{item.[3]</li>
))}
</ul>
);
}Use the map method to loop over items. Use a unique key like id for each list item. Display the name property inside the list item.