Complete the code to create a simple reusable button component in React.
function Button({ label }) {
return <button>[1];</button>;
}The label prop is used to display the button text inside the button element.
Complete the code to pass a click handler to the reusable button component.
function Button({ label, [1] }) {
return <button onClick={handleClick}>{label}</button>;
}The prop onClick is the standard React event handler for button clicks.
Fix the error in the reusable button component to correctly call the click handler passed as a prop.
function Button({ label, onClick }) {
return <button onClick=[1]>{label}</button>;
}You should pass the function reference onClick directly, not call it immediately.
Fill both blanks to create a reusable input component that updates its value on change.
function TextInput({ value, [1] }) {
return <input type="text" value={value} onChange=[2] />;
}The prop onChange is used to handle input changes, and handleChange is the function passed to update the value.
Fill all three blanks to create a reusable list component that renders items with keys.
function ItemList({ items }) {
return (
<ul>
{items.map([1] => (
<li key=[2]>[3]</li>
))}
</ul>
);
}We map over items using item as the variable. The key uses item.id for uniqueness, and we display item.name inside the list item.