Complete the code to create a React component that returns a heading using JSX.
function Hello() {
return ([1]);
}JSX looks like HTML inside JavaScript. Here, <h1>Hello, world!</h1> is JSX that React understands and renders as a heading.
Complete the JSX code to display a paragraph with the text 'Welcome to React!'.
const element = [1];JSX uses HTML-like tags. Here, <p>Welcome to React!</p> is the correct JSX to create a paragraph element.
Fix the error in this JSX code by completing the blank.
const element = <div>[1]Hello</div>;incorrectly
In JSX, to add a space between elements or text, use curly braces with a string: {' '}. Plain quotes inside tags cause errors.
Fill both blanks to create a JSX expression that shows a list of items from an array.
const items = ['Apple', 'Banana', 'Cherry']; const list = <ul>[1].map((item) => <li key={item}>[2]</li>)</ul>;
We use items.map to loop over the array and item to show each fruit inside list items.
Fill all three blanks to create a React component that uses JSX to display a greeting with a name prop.
function Greeting([1]) { return <h1>Hello, [2]!</h1>; } const element = <Greeting [3]="Alice" />;
The component receives a prop called name. We use it inside JSX and pass it as an attribute when using the component.