function MyInput() { return <input className="my-class" />; }
In JSX, the HTML attribute class cannot be used because 'class' is a reserved JavaScript keyword, causing a syntax error in the transpiled code. Use className instead.
function Image() { return <img src="logo.png" />; }
In JSX, void elements like <img> should be self-closed with /> to follow XML-like syntax rules. Using a separate closing tag is discouraged and may trigger warnings.
function Button() { return <button onClick={() => alert('Clicked!')}>Click me</button>; }
JSX requires event handler attributes to be camelCase. Using onclick instead of onClick causes React to not recognize the event handler, which can cause errors or unexpected behavior.
alt attribute in the rendered <img> element?function Logo() { const name = 'React'; return <img src="logo.png" alt={name + ' Logo'} />; }
JSX allows embedding JavaScript expressions inside curly braces. The expression {name + ' Logo'} evaluates to the string 'React Logo', which is assigned to the alt attribute.
<label> element uses htmlFor instead of the HTML attribute for. Why is this change necessary?The word for is a reserved keyword in JavaScript used for loops. JSX is JavaScript syntax, so using for as an attribute name would cause syntax errors. React uses htmlFor instead to avoid this conflict.