The class attribute is commonly used in HTML, but since JSX is rendered as JavaScript and class is a reserved keyword in JavaScript, you must use className instead in JSX.
Use the className attribute instead. |
JSX addresses this by using className instead. When JSX is rendered, it converts className attributes into class attributes.
In JSX, use the className attribute instead of class.
const |
React supports if statements, but they cannot be used directly inside JSX. To implement conditionals in JSX, place the if statements outside of the JSX or use a ternary expression.
Place if statements outside of the JSX code.
Display “Hello” if x is less than 10; otherwise, display “Goodbye.”
const const |
Use a ternary expression instead.
Use a ternary expression to display “Hello” if x is less than 10, otherwise display “Goodbye.”
const const |
To embed a JavaScript expression inside JSX, wrap the JavaScript code with curly braces {} . |