React: The First Steps
React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It lets you compose complex UIs from small and isolated pieces of code called components.
What is a Component?
Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called "props") and return React elements describing what should appear on the screen. The golden rule is that component names must always start with a capital letter (e.g., Welcome, not welcome).
JSX: JavaScript XML
JSX is a syntax extension for JavaScript. It produces React "elements". We recommend using it with React to describe what the UI should look like. Although it looks like HTML, there are stricter rules:
- Return a single root element: To return multiple elements from a component, wrap them with a single parent tag or a
<Fragment>. - Close all the tags: Tags like
<img>must become self-closing:<img />. - camelCase all most things: JSX turns into JavaScript, and attributes written in HTML become keys of JavaScript objects. Therefore,
classbecomesclassName, andtabindexbecomestabIndex.
Rendering to the DOM
To render a React element into a root DOM node, pass the DOM element to createRoot(), then pass the React element to root.render().
View Full Transcript+
This section contains the full detailed transcript covering why React was created, the concept of Declarative Programming vs Imperative DOM manipulation, and the architectural benefits of the Virtual DOM (how React batches updates for performance).
