JavaScript Curriculum
What is React
easyThe coffee shop menu works with vanilla DOM manipulation, but every feature adds more querySelector calls and manual DOM updates. React solves this — describe the UI as a function of state, and React handles all the DOM work.
What is React
React is a JavaScript library for building user interfaces. Released by Facebook in 2013, it introduced a new way of thinking about UI — instead of manually updating the DOM, you describe what the UI should look like and React figures out how to get there efficiently.
The Virtual DOM — Why React Exists
Vanilla DOM manipulation works, but it gets messy fast. Every feature means more querySelector calls, more manual state tracking, more subtle bugs. React solves this with the Virtual DOM:
JSX — HTML in Your JavaScript
React introduces JSX — a syntax extension that lets you write HTML-like markup directly in JavaScript. Babel compiles it to React.createElement() calls before the browser sees it:
<h1 className="title">Hello React</h1>
The React Mental Model
Four core ideas that underpin everything in React:
A React component is a pure function. Give it the same props and state — it always returns the same UI. React calls your function whenever state changes and updates the screen.
// React calls this whenever state changes: function CartButton({ count }) { return ( <button> Cart ({count}) </button> ) } // You never touch the DOM. // React handles re-rendering.
Your Challenge
Write a JSX snippet for a menu card: a div.card containing an h3 with the item name and a p.price with the price. Then rewrite the same thing as nested React.createElement() calls to understand what JSX compiles to.
Challenge
In your own words: what is the Virtual DOM and why does it exist? What does 'declarative UI' mean compared to imperative DOM manipulation? Write a JSX expression that renders a div with a class of 'card' containing an h3 and a p element.
What is React
easyThe coffee shop menu works with vanilla DOM manipulation, but every feature adds more querySelector calls and manual DOM updates. React solves this — describe the UI as a function of state, and React handles all the DOM work.
What is React
React is a JavaScript library for building user interfaces. Released by Facebook in 2013, it introduced a new way of thinking about UI — instead of manually updating the DOM, you describe what the UI should look like and React figures out how to get there efficiently.
The Virtual DOM — Why React Exists
Vanilla DOM manipulation works, but it gets messy fast. Every feature means more querySelector calls, more manual state tracking, more subtle bugs. React solves this with the Virtual DOM:
JSX — HTML in Your JavaScript
React introduces JSX — a syntax extension that lets you write HTML-like markup directly in JavaScript. Babel compiles it to React.createElement() calls before the browser sees it:
<h1 className="title">Hello React</h1>
The React Mental Model
Four core ideas that underpin everything in React:
A React component is a pure function. Give it the same props and state — it always returns the same UI. React calls your function whenever state changes and updates the screen.
// React calls this whenever state changes: function CartButton({ count }) { return ( <button> Cart ({count}) </button> ) } // You never touch the DOM. // React handles re-rendering.
Your Challenge
Write a JSX snippet for a menu card: a div.card containing an h3 with the item name and a p.price with the price. Then rewrite the same thing as nested React.createElement() calls to understand what JSX compiles to.
Challenge
In your own words: what is the Virtual DOM and why does it exist? What does 'declarative UI' mean compared to imperative DOM manipulation? Write a JSX expression that renders a div with a class of 'card' containing an h3 and a p element.