Reading — step 1 of 5
Read
~1 min readReactive Foundations
Components
A component = a function (or class) returning a vnode.
python
Two component types:
- Function components: just a function. Modern default.
- Class components (React legacy): class with render method + lifecycle methods.
Function components only need props as input.
Composition:
- Components nest like HTML elements.
- Each component is reusable.
- Pass data via props (top-down).
Props:
- Read-only data passed from parent to child.
- Can include functions (callbacks).
Children prop:
- Special prop: nested vnodes.
<Card>{children}</Card>→ children passed asprops.children.
python
Render flow:
- Root vnode tree.
- For each function-typed vnode: call function with props, get inner vnode.
- Recursively expand until all are HTML elements + text.
- Convert to real DOM.
Component model is the central abstraction in React/Vue/Svelte. Used for:
- Reusability.
- Encapsulation (each component manages its own state).
- Composition (build big from small).
Single-file components (Vue, Svelte): HTML + CSS + JS in one file. React keeps separate (CSS-in-JS or external).
Class vs function: React deprecated classes for new code. Hooks (next lesson) made functions powerful.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…