Complete the code to access the prop name inside the component.
function Greeting(props) {
return <h1>Hello, {props.[1]!</h1>;
}state instead of props to access data.The props object contains the data passed to the component. To read the name prop, use props.name.
Complete the code to pass a prop called age with value 30 to the User component.
<User [1]={30} />
state or setAge instead of the prop name.Props are passed as attributes to components. To pass an age prop, write age={30}.
Fix the error in the code by completing the blank to prevent modifying props directly.
function Counter(props) {
// Incorrect: props.count = props.count + 1;
const newCount = props.[1] + 1;
return <p>{newCount}</p>;
}props.count directly.Props are read-only. You can read props.count but must not assign to it. Instead, calculate a new value without changing props.
Fill both blanks to correctly destructure props and use the title prop inside the component.
function Header([1]) { return <h2>{ [2] }</h2>; }
state instead of props.{props} which doesn't destructure individual props correctly.Destructuring extracts individual props into function parameters. Write function Header({title}) and use {title} directly in JSX. Both blanks are title.
Fill all three blanks to create a component that receives firstName and lastName props and displays the full name.
function FullName([1], [2]) { return <p>{ [3] + ' ' + [2] }</p>; }
The component destructures firstName and lastName from props. Then it uses them to display the full name. The first and third blanks are firstName, the second is lastName.