Complete the code to create a React component that only renders a greeting message.
function Greeting() {
return <h1>{"Hello, friend!"}</h1>;
}In JSX, text content between tags must be a JavaScript string literal like "Hello, friend!" without extra quotes around the entire string.
Complete the code to separate the button's click logic into a handler function.
function Clicker() {
function [1]() {
alert('Clicked!');
}
return <button onClick={handleClick}>Click me</button>;
}The function name must match the event handler used in JSX for clarity and correctness.
Fix the error in the code by completing the import statement for React hooks.
import React, { [1] } from 'react'; function Counter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>{count}</button>; }
The useState hook is needed to create state in the Counter component.
Fill both blanks to create a component that separates display and logic.
function Display({ [1] }) {
return <p>{message}</p>;
}
function Container() {
const message = 'Hello from container!';
return <Display [2]={message} />;
}The prop name must match between the Display component's parameter and the Container's prop passed.
Fill all three blanks to create a reusable button component with separated concerns.
function Button({ [1], [2], [3] }) {
return <button onClick={onClick} aria-label=[3]>{label}</button>;
}
function App() {
function handleClick() {
alert('Button pressed');
}
return <Button [1]="Press me" [2]={handleClick} [3]="Press me button" />;
}Props 'label', 'onClick', and 'ariaLabel' separate button text, click logic, and accessibility label.