REACT & NEXT.JS / 1. COMPONENTS & JSX
Components & JSX
The building blocks — everything in React is a component
EXPLANATION
A component is a function that returns JSX (JavaScript XML — HTML-like syntax that compiles to React.createElement calls).
Rules:
• Component names MUST start with uppercase (lowercase = HTML element)
• Must return a single root element (use <> fragment if needed)
• JSX expressions go inside {}
Props: data passed from parent to child. Read-only — never mutate props.
Children: special prop — content between component tags.
Component composition: the React way of reusing UI. Instead of inheritance, you compose small components into larger ones.
Key JSX gotchas:
• class → className (class is reserved in JS)
• for → htmlFor (same reason)
• style takes an object: style={{ color: "red" }}
• All tags must be closed: <img /> not <img>
• Conditional rendering: {condition && <Component />} or ternary
• List rendering: always provide a unique key propDIAGRAM
Component tree:
<App>
<Navbar logo="deepdocs" />
<main>
<Sidebar>
<NavItem href="/rag">RAG & LLMs</NavItem>
<NavItem href="/ml">Machine Learning</NavItem>
</Sidebar>
<Article>
<h1>{title}</h1>
<CodeBlock code={code} lang="python" />
</Article>
</main>
</App>
Data flows DOWN (props), events bubble UP (callbacks)
Parent → Child: props
Child → Parent: callback functions passed as propsCODE