🖨 Print / Save PDF
← Lesson
BitWith
Bite
React · Quick Reference
Lesson 3 — JSX Rules
Cheat Sheet
React
In one line:
JSX compiles to JS function calls, which is why it has its own small set of rules different from plain HTML.
The 7 Rules
1
One parent element (or Fragment <>)
2
className instead of class
3
Self-close empty tags: <img />
4
JS in { } curly braces
5
camelCase events: onClick
6
style={{ color:"red" }}
7
Arrays need a key prop
Example
{isAdmin && <span>Admin</span>} {age >= 18 ? <Adult/> : <Minor/>} <h2 style={{color:"gold"}}>{name}</h2> {list.map((x,i) => <span key={i}>{x}</span>)}