Successfully added
React
by Patrik
Understanding JSX
JSX may look like HTML, but it’s actually JavaScript. When used correctly, it brings power and clarity to React development.
Why Use JSX?
- It’s familiar to anyone who has written HTML.
- You can mix logic and layout using
{}
for JavaScript expressions. - JSX is compiled into fast and efficient React code.
Key JSX Rules
- Use
className
instead ofclass
. - Self-closing elements like
<img />
. - Wrap multiple elements in one parent:
<div>
or<>
.
Example:
function Greeting() {
return <h1>Hello, world!</h1>;
}
Common Mistakes
- Forgetting to close tags.
- Using
class
instead ofclassName
. - Returning multiple sibling elements without a wrapper.
jsx
react
syntax
javascript
components
Referenced in:
Comments