liveBook · Manning

React

As explained in React Quickly, Second Edition

React is a JavaScript library for building user interfaces from reusable components and rendering dynamic data.

Need to put changing data on a page? React is a JavaScript UI library for building reusable components and rendering them in the browser. It can power one interactive widget or form the UI layer of a larger application. section 1.0 section 1.3

Listing 1.2 Creating and rendering an h1 element
const reactElement = React.createElement(            #1
  'h1',                                              #1
  null,                                              #1
  'Hello world!!!'                                   #1
);                                                   #1
const domNode = document.getElementById('root');     #2
const root = ReactDOM.createRoot(domNode);           #3
root.render(reactElement);                           #4

Start with a heading, no JSX required. React.createElement creates the element; ReactDOM.createRoot selects the page container, and render displays it. section 1.4.2

The heading example uses plain JavaScript. JSX offers a more concise, HTML-like way to describe React elements, but it is optional and needs preprocessing before a browser can run it. React Core handles composable UI components; ReactDOM supplies rendering methods for the web. section 1.4.1 section 1.7

As the UI grows, keep these boundaries in mind:

  • Describe the desired UI rather than manually updating the DOM step by step. Components let you reuse UI and its logic; an <Autocomplete charNum="4"/> component is one possible drop-in control. section 1.1.1 section 1.0
  • React focuses on the UI layer, not every part of an application. A larger stack may add routing, data, and styling libraries. section 1.3.2
  • A React UI can be added to a server-rendered site without changing its backend, but mixing React with another framework inside one single-page application is much harder. section 1.3
  • Package choice brings maintenance: keep dependencies and their versions in order as a React stack grows. section 1.2

Grow a menu one step at a time

Begin with the HTML for the desired menu. Turn it into a component tree and equivalent JSX while it is still static. Then add state and other behavior incrementally. For interaction, a supported event property on a JSX element is treated as a listener, which React adds and removes as the component mounts and unmounts. section 11.7 section 8.1

How React Quickly, Second Edition covers it

How deep it goes
Works through plain-JavaScript element creation and rendering, then sketches an incremental component-tree workflow rather than renderer internals.
Examples
Uses a Hello World heading and an incrementally built website menu.
What it assumes
Assumes a text editor, terminal familiarity, npm 5.2+, and a modern browser; starts React without JSX.
What you can do after
Build it from scratch: render a heading with React.createElement and ReactDOM.createRoot(...).render(), then plan a menu as a component tree.
How it connects
Connects components and JSX to ReactDOM rendering and to separate routing, data, and styling libraries.

Also explained in

Compare how 5 books explain React →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Quickly, Second Edition. The section links point to the parts of the book it draws on.