Complete the code to define a simple React functional component named Greeting.
function Greeting() {
return <h1>[1];</h1>;
}The component must return JSX with a string inside quotes. So the correct answer is a string literal inside quotes.
Complete the code to use React's useState hook to create a counter state variable.
import React, { [1] } from 'react'; function Counter() { const [count, setCount] = useState(0); return <p>{count}</p>; }
useState is the hook to create state in functional components.
Fix the error in the component by completing the code to correctly handle a button click event.
function Clicker() {
const [clicked, setClicked] = React.useState(false);
return <button onClick=[1]>Click me</button>;
}The onClick expects a function, so we pass an arrow function that calls setClicked(true).
Fill both blanks to create a functional component that accepts props and displays a greeting.
function Welcome([1]) { return <h2>Hello, [2]!</h2>; }
The component destructures the prop 'name' and uses it directly inside JSX.
Fill all three blanks to create a functional component that maps over an array of items and renders them as list elements.
function ItemList({ items }) {
return (
<ul>
{items.map(([1], [2]) => (
<li key=[3]>[1]</li>
))}
</ul>
);
}We name the first parameter 'item', the second 'index', and use 'index' as the key for list items.