Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Stoyan Stefanov

Hit the ground running with React, the open source technology from Facebook for building rich web applications fast. Updated for the latest React release, the React: Up & Running: Building Web Applications, 2nd Edition of this hands-on guide shows you how to build React components and organize them into maintainable large-scale apps. If you’re familiar with JavaScript syntax, you’re ready to get started. Set up React and write your first “Hello, World” web app Create and use custom React components alongside generic DOM components Build a data table component that lets you edit, sort, search, and export its contents Master the JSX syntax Use built-in Hooks and create your own custom ones Manage the app’s data flow with reducers and contexts Use Create React App to take care of the build process and focus on React itself Build a complete custom app that lets you store data on the client Through the course of this React: Up & Running: Building Web Applications, 2nd Edition book, author Stoyan Stefanov helps web developers and programmers build a complete single-page application. You’ll quickly learn why some developers consider React the key to the web app development puzzle.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on, example-driven guide to React for developers who know basic JavaScript, walking you from a "Hello World" setup through building a complete, editable data-table app while mastering components, JSX, Hooks, and state management. 【Book Arc】 - **Opening (~0%–6%)**: Sets up the development environment with React, ReactDOM, and Babel, then builds a first "Hello World" app. It introduces the core idea that React manages UI updates by pointing it at a DOM placeholder, and explains why JSX (with Babel transpilation) makes code more readable than raw `React.createElement` calls. - **Early (~6%–19%)**: Dives into JSX syntax details—whitespace, comments, HTML entities, spread attributes, and differences from HTML (like `className` instead of `class`). It also introduces custom components, showing both function and class definitions, and explains the component lifecycle (mounting, updating, unmounting). - **Early (~19%–34%)**: Explores component state and props in depth, using a `TextAreaCounter` example. It covers event handling (contrasting React's synthetic events with manual DOM delegation), `setState`, `defaultProps`, and lifecycle methods like `shouldComponentUpdate`. The section emphasizes that state changes trigger re-renders, which is React's core benefit. - **Middle (~34%–47%)**: Builds the book's centerpiece—an "Excel" data table component. It starts with rendering headers and rows via `map()`, then adds prop types for validation, sorting, inline editing (with a `data-row` index), and a search/filter feature. The focus is on managing complex UI state in a single component. - **Late (~47%–end)**: Continues the Excel component with cleanup of event handlers (e.g., removing `keydown` listeners) and likely transitions to functional components with Hooks, reducers, and contexts for data flow, as promised in the blurb. The final chapters cover building a complete client-side storage app. 【Key Takeaways】 - **React's minimal API is the foundation** (Early): All React functionality is accessed via the `React` object, with a deliberately small set of methods. This simplicity means you can focus on component logic rather than memorizing a large framework API. - **JSX is syntactic sugar for `createElement`** (Early): JSX looks like HTML but must be transpiled by Babel. It improves readability significantly, but you must learn its quirks—like `className` instead of `class`, camelCase attributes, and treating `style` as an object—to avoid bugs. - **Components are just functions (or classes) returning UI** (Early): A custom component is simply a function returning `React.createElement` or JSX. Function components are preferred for the future, but class components are still fully supported, so learning both is worthwhile. - **State changes drive all UI updates** (Early): Calling `setState()` triggers a re-render of the component. This is React's core value proposition—you focus on data, and React handles the DOM updates, eliminating manual `getElementById` and event delegation boilerplate. - **Prop types catch errors early** (Middle): Since JavaScript lacks type checking, `PropTypes` (a separate library since React 15.5) lets you specify expected prop shapes (e.g., `arrayOf(string)`). This surfaces developer errors early, which is crucial for larger projects and teams. - **Complex UI state can be managed in one component** (Middle): The Excel table demonstrates how to handle sorting, editing, and searching by keeping state like `sortby`, `edit`, and `search` in a single component. Using `data-row` attributes and index tracking makes inline editing feasible. - **Cleanup is a "good citizen" practice** (Late): When components unmount, they should remove event listeners and intervals (e.g., `keydown` handlers, replay timers). This prevents memory leaks and bugs in real applications where components are frequently added and removed. 【Reading Tips】 - **Skim the early setup chapters (0–6%)** if you're already comfortable with npm and build tools; the key takeaway is the `ReactDOM.render` pattern and the Babel `<script type="text/babel">` trick for learning without a build step. - **Deep-read the JSX chapter (6–9%)**—it's dense with syntax gotchas (whitespace, comments, spread attributes) that will save you debugging time later. Pay special attention to the "Differences Between JSX and HTML" section. - **Follow along with the Excel component (34–47%)** by coding it yourself; it's the book's practical core. If you get lost in the `map()` loops, try the verbose v3 version before the terse arrow-function v5. - **Don't skip the lifecycle methods section (19–28%)**—`shouldComponentUpdate` and `componentWillUnmount` are essential for performance and cleanup, even if you later switch to Hooks. - **Expect a syntax shift in the late chapters**—the book transitions from class components to function components with Hooks. If you're new to Hooks, reread the state/props concepts from earlier chapters, as the author notes the differences are "just syntax." 【Coverage Limits】 This guide covers the book's progression through components, JSX, state, and the Excel table example, but the excerpts do not cover the final chapters on Hooks, reducers, contexts, or the complete client-storage app in detail.
Excerpt 1
73 Editing Data 75 Searching 76 Lifecycles in a World of Hooks 77 Troubles with Lifecycle Methods 77 useEffect() 78 Cleaning Up Side Effects 79 Trouble-Free...
View in text
Excerpt 2
PE html> <html> <head> <title>Hello React+JSX</title> <meta charset="utf-8"> </head> <body> <div id="app"> <!-- my app renders here --> </div> <script src="r...
View in text
Excerpt 3
preceding code, using _ as a name of a function argument is a convention signaling to a future reader of the code, “I know there’s another argument in the fu...
View in text
Excerpt 4
this.preSearchData = null; } else { this.preSearchData = this.state.data; this.setState({ search: true, } } The last thing to do is implement the search() fu...
View in text
Excerpt 5
xcel({headers, initialData}) { function sort(e) { // implement me } return ( <table> </table> } The sort() function figures out which column to sort by (usin...
View in text
Excerpt 6
or and adopts it as a convenience when defining properties. Imagine you have a collection of attributes you want to pass to an <a> component: Spread Attribut...
View in text
Excerpt 7
ndency from a shared place (node_modules). CSS In src/index.js you can see how CSS is treated just like another module: import './index.css'; The src/index.c...
View in text
Excerpt 8
brary via a simple configuration. More on this in a moment. Testing the <FormInput> in the discovery app (see Figure 7-11): <h2>Form inputs</h2> <table class...
View in text
Tags
AI categories
Programming LanguageWeb TechnologyJavaScript
ISBN: 1492051462
Publisher: O'Reilly Media
Publish Year: 2021
Language: English
Pages: 233
File Format: PDF
File Size: 15.3 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…