Read Anytime AnywhereEasy Ebook Downloads at ebookmeta.com
React in Action 1st Edition Mark Tielens Thomas
https://ebookmeta.com/product/react-in-action-1st-edition-
mark-tielens-thomas/
OR CLICK HERE
DOWLOAD EBOOK
Visit and Get More Ebook Downloads Instantly at https://ebookmeta.com
2.
Recommended digital products(PDF, EPUB, MOBI) that
you can download immediately if you are interested.
Cloud Native Spring in Action 1st Edition Thomas Vitale
https://ebookmeta.com/product/cloud-native-spring-in-action-1st-
edition-thomas-vitale/
ebookmeta.com
Administrative Law in Action : Immigration Administration
1st Edition Robert Thomas
https://ebookmeta.com/product/administrative-law-in-action-
immigration-administration-1st-edition-robert-thomas/
ebookmeta.com
DuckDB in Action MEAP V03 Mark Needham Michael Hunger
Michael Simons
https://ebookmeta.com/product/duckdb-in-action-meap-v03-mark-needham-
michael-hunger-michael-simons/
ebookmeta.com
Australian Practical Accounting Guide Stephen J. Marsden
https://ebookmeta.com/product/australian-practical-accounting-guide-
stephen-j-marsden/
ebookmeta.com
3.
Leveled Text DependentQuestion Stems Social Studies 1st
Edition Niomi Henry
https://ebookmeta.com/product/leveled-text-dependent-question-stems-
social-studies-1st-edition-niomi-henry/
ebookmeta.com
Fourier Series Fourier Transform and Their Applications to
Mathematical Physics Instructor Solution Manual Solutions
1st Edition Valery Serov
https://ebookmeta.com/product/fourier-series-fourier-transform-and-
their-applications-to-mathematical-physics-instructor-solution-manual-
solutions-1st-edition-valery-serov/
ebookmeta.com
Spanish Verb Tenses Dorothy Richmond
https://ebookmeta.com/product/spanish-verb-tenses-dorothy-richmond/
ebookmeta.com
Games and Education Designs in and for Learning 1st
Edition Hans Christian Arnseth
https://ebookmeta.com/product/games-and-education-designs-in-and-for-
learning-1st-edition-hans-christian-arnseth/
ebookmeta.com
Her Dragon Mate Awaken the Dragon Book 4 1st Edition Milly
Taiden Ava Hunter
https://ebookmeta.com/product/her-dragon-mate-awaken-the-dragon-
book-4-1st-edition-milly-taiden-ava-hunter/
ebookmeta.com
4.
How to Diagnoseand Fix Everything Electronic Second
Edition Michael Jay Geier
https://ebookmeta.com/product/how-to-diagnose-and-fix-everything-
electronic-second-edition-michael-jay-geier/
ebookmeta.com
vii
brief contents
PART 1MEET REACT.................................................................1
1 ■ Meet React 3
2 ■ <Hello World />: our first component 22
PART 2 COMPONENTS AND DATA IN REACT ..............................57
3 ■ Data and data flow in React 59
4 ■ Rendering and lifecycle methods in React 77
5 ■ Working with forms in React 111
6 ■ Integrating third-party libraries with React 129
7 ■ Routing in React 151
8 ■ More routing and integrating Firebase 170
9 ■ Testing React components 192
PART 3 REACT APPLICATION ARCHITECTURE..........................219
10 ■ Redux application architecture 221
11 ■ More Redux and integrating Redux with React 251
12 ■ React on the server and integrating React Router 277
13 ■ An introduction to React Native 313
Licensed to Samir Mashlum <smashlum@gmail.com>
ix
contents
preface xv
acknowledgments xvii
aboutthis book xix
about the author xxii
about the cover illustration xxiii
PART 1 MEET REACT.......................................................1
1 Meet React 3
1.1 Meet React 4
Who this book is for 6 ■
A note on tooling 7
Who uses React? 7
1.2 What does React not do? 9
Tradeoffs of React 10
1.3 The virtual DOM 12
The DOM 13 ■
The virtual DOM 15 ■
Updates and
diffing 16 ■
Virtual DOM: Need for speed? 17
1.4 Components: The fundamental unit of React 17
Components in general 17 ■
Components in React: Encapsulated
and reusable 18
1.5 React for teams 19
Licensed to Samir Mashlum <smashlum@gmail.com>
15.
CONTENTS
x
2 <Hello World/>: our first component 22
2.1 Introducing React components 24
Understanding the application data 26 ■ Multiple components:
Composition and parent-child relationships 28 ■ Establishing
component relationships 28
2.2 Creating components in React 31
Creating React elements 31 ■ Rendering your first component 34
Creating React components 36 ■ Creating React classes 37
The render method 37 ■ Property validation via PropTypes 38
2.3 The life and times of a component 42
A React state of mind 43 ■ Setting initial state 44
2.4 Meet JSX 52
Creating components using JSX 53 ■ Benefits of JSX and
differences from HTML 55
PART 2 COMPONENTS AND DATA IN REACT ....................57
3 Data and data flow in React 59
3.1 Introducing state 60
What is state? 60 ■
Mutable and immutable state 63
3.2 State in React 65
Mutable state in React: Component state 65 ■
Immutable state in
React: Props 69 ■
Working with props: PropTypes and default
props 70 ■
Stateless functional components 71
3.3 Component communication 73
3.4 One-way data flow 74
4 Rendering and lifecycle methods in React 77
4.1 Getting set up with the Letters Social repo 78
Getting the source code 80 ■
Which version of node should
I use? 80 ■
Note on tooling and CSS 81 ■
Deploying 81
The API server and database 81 ■
Running the app 82
4.2 The render process and lifecycle methods 82
Introducing lifecycle methods 82 ■
Types of lifecycle methods 84
Initial and “will” methods 88 ■
Mounting components 89
Updating methods 93 ■
Unmounting methods 96
Catching errors 98
4.3 Starting to create Letters Social 102
Licensed to Samir Mashlum <smashlum@gmail.com>
16.
CONTENTS xi
5 Workingwith forms in React 111
5.1 Creating posts in Letters Social 112
Data requirements 112 ■ Component overview and
hierarchy 113
5.2 Forms in React 115
Getting started with forms 115 ■ Form elements and events 116
Updating state in forms 120 ■ Controlled and uncontrolled
components 121 ■ Form validation and sanitization 123
5.3 Creating new posts 126
6 Integrating third-party libraries with React 129
6.1 Sending posts to the Letters Social API 130
6.2 Enhancing your component with maps 132
Creating the DisplayMap component using refs 133
Creating the LocationTypeAhead component 139
Updating CreatePost and adding maps to posts 145
7 Routing in React 151
7.1 What is routing? 152
Routing in modern front-end web applications 153
7.2 Creating a router 154
Component routing 155 ■
Creating the <Route />
component 156 ■
Starting to build the <Router/>
component 157 ■
Matching URL paths and parameterized
routing 160 ■
Adding routes to the Router component 162
8 More routing and integrating Firebase 170
8.1 Using the router 171
Creating a page for a post 177 ■
Creating a <Link/>
component 178 ■
Creating a <NotFound/> component 182
8.2 Integrating Firebase 183
Ensuring a user is logged in 187
9 Testing React components 192
9.1 Types of testing 194
Why test? 195
9.2 Testing React components with Jest, Enzyme, and React-
test-renderer 197
Licensed to Samir Mashlum <smashlum@gmail.com>
17.
CONTENTS
xii
9.3 Writing yourfirst tests 199
Getting started with Jest 199 ■ Testing a stateless functional
component 201 ■ Testing the CreatePost component without
Enzyme 205 ■ Test coverage 213
PART 3 REACT APPLICATION ARCHITECTURE................219
10 Redux application architecture 221
10.1 The Flux application architecture 223
Meet Redux: A variation on Flux 226 ■
Getting set up for
Redux 227
10.2 Creating actions in Redux 229
Defining action types 230 ■
Creating actions in Redux 232
Creating the Redux store and dispatching actions 232
Asynchronous actions and middleware 235 ■
To Redux or
not to Redux? 242 ■
Testing actions 245 ■
Creating custom
Redux middleware for crash reporting 247
11 More Redux and integrating Redux with React 251
11.1 Reducers determine how state should change 252
State shape and initial state 253 ■
Setting up reducers to respond
to incoming action 254 ■
Combining reducers together in our
store 261 ■
Testing reducers 262
11.2 Bringing React and Redux together 264
Containers vs. presentational components 264 ■
Using
<Provider /> to connect components to the Redux store 267
Binding actions to component event handlers 272 ■
Updating
your tests 274
12 React on the server and integrating React Router 277
12.1 What is server-side rendering? 278
Digging into server-side rendering 280
12.2 Why render on the server? 282
12.3 You might not need SSR 285
12.4 Rendering components on the server 286
12.5 Switching to React Router 292
Setting up React router 293
12.6 Handling authenticated routes with React router 297
12.7 Server rendering with data-fetching 301
Licensed to Samir Mashlum <smashlum@gmail.com>
18.
CONTENTS xiii
13 Anintroduction to React Native 313
13.1 Introducing React Native 314
13.2 React and React Native 317
13.3 When to use React Native 319
13.4 The simplest “Hello World” 321
13.5 Where to go next 324
index 327
Licensed to Samir Mashlum <smashlum@gmail.com>
xv
preface
When I firststarted learning about and using React, the JavaScript community was just
beginning to settle down from a period of rapid innovation and disruption (read: tur-
bulence). React was gaining in popularity, but the JavaScript community still seemed
like the Wild West in many ways. I was excited about React as a technology because it
showed real promise. The mental model seemed solid, components made building
UIs easier, the API was flexible and expressive, and the whole project seemed like it
was “just right.” Postulations about its API surface, usability, and theoretical underpin-
nings aside, there was also the fact that it seemed really cool to me and I enjoyed work-
ing with it.
Since then, quite a bit has changed—and at the same time not much has changed at
all. React has remained largely the same in terms of its fundamental concepts and API,
although a body of knowledge and best practices have emerged and evolved, and more
people use it. An open source ecosystem of libraries and related technologies has flour-
ished. There are conferences, meetups, and communities that involve React to one
degree or another. In version 16, the React core team rewrote the internal architecture
of React in a way that both maintained backward compatibility and paved the way for a
slew of future innovations. All these “changes without too much change” point to what I
believe is one of React’s greatest strengths: a maintained tension between stability and
innovation that drives adoption without leaving people in the dust.
For all these reasons and more, React has continued to take hold as a technology
and has only become more popular. It’s in use in one way or another at many large
companies, at countless startups, and at every sort of company in between. And many
Licensed to Samir Mashlum <smashlum@gmail.com>
21.
PREFACE
xvi
companies that don’tcurrently use React are trying to switch over to it to modernize
their frontend applications.
React hasn’t only grown in popularity with respect to the web—it’s also made
inroads into other platforms. React Native, the port of React to mobile platforms, has
also been a major innovation. It demonstrates React’s “learn once, write anywhere”
approach. This idea of React as a platform means you’re not limited to using it for
browser-based applications.
Let’s forget the hype around React and focus on what this book should do for you.
My primary hopes for React in Action are that it equips you to understand and work
with React effectively and, even more, that it makes you better at building user inter-
faces overall, even if in a small way. My aim is not to engage in buzzword-driven devel-
opment or push you toward “magical” technologies. Rather, my wager is that a robust
mental model and deep understanding coupled with practical examples will put you
in a place to do incredible things with React, whether on your own or with others.
Licensed to Samir Mashlum <smashlum@gmail.com>
22.
xvii
acknowledgments
Don’t wait forthings to be perfect before you share them with others.
Show early and show often. It’ll be pretty when we get there, but it won’t
be pretty along the way.
—Ed Catmull, Creativity, Inc.: Overcoming the Unseen Forces That Stand
in the Way of True Inspiration
Few worthwhile endeavors are undertaken alone. In many cases, a single person or
handful of people is entirely credited with success, but this singular attribution belies
the larger network of contributors who work toward an end. Those who would claim
to have “done it alone” often fail to realize the ways in which others have helped them,
whether by example or by instruction. What’s more, failure to realize the strength of
working in a community pushes success and excellence even further out of reach.
Working alone means being limited to what you, and only you, can do. Collaboration
provides a path to excellence by opening us to humility, new ideas, different perspec-
tives, and invaluable feedback.
I won’t be so foolish as to think, even for a second, that I’ve written this book by
myself. My fingers pushed keys, and my name will be on the cover, but that doesn’t
mean this was a one-person show. No, this book—like all the things in my life that I’m
grateful for—is the result of a rich community of smart, humble, loving people willing
to be patient, kind, and sometimes firm with me.
First, I would like to thank my wife, Haley. She’s my joy, my best friend, my creative
partner. She’s put up with this book for a long time. Late nights, more late nights, and
endless talking about the book. She—the brilliant and better writer—helped me when
Licensed to Samir Mashlum <smashlum@gmail.com>
23.
ACKNOWLEDGMENTS
xviii
I had writer’sblock. She encouraged me when I felt as if finishing the book was impos-
sible. She’s always constant in love and in prayer. She’s always comforted me in low
times, challenged me when I doubted myself, and celebrated with me in times of joy.
She’s been incredible through the entire process and I can’t wait to return the favor
and help her with the many books she’ll write in the future. I’m always and immeasur-
ably grateful for her.
I would also like to thank the other people in my life who have supported me in
this process. I’m humbled and thankful to have an incredible family. My mom and
dad, Annmarie and Mitchell, have been encouraging throughout the writing of this
book (and my whole life). They’ve also promised to read it in its entirety, though I
won’t hold them to that. My brothers, David and Peter, have also been supportive and
encouraging. They haven’t promised to read the book, though, so I’ll be reading it
aloud to them for the next year (or however long it takes). My friends from church,
childhood, and work have also been incredibly helpful. They did me the great service
of always asking, “Is it done yet?” to spur me on, and they put up with my explanations
of React. I would also like to thank my professors, especially Dr. Diana Pavlac Glyer, for
teaching me to think and to write.
The folks at Manning have been very helpful in this process. I want to extend a spe-
cial thank you to Marina Michaels (development editor), Nickie Bruckner (technical
development editor), and German Frigerio (technical proofer). They spent countless
hours reading and helping with my writing. This book wouldn’t exist without them. I
would also like to thank Brian Sawyer for reaching out to me about writing the book
and Marjan Bace for giving me the opportunity to write the book in the first place.
Everyone at Manning is committed to helping people everywhere learn important,
impactful skills and concepts in effective ways. I firmly believe in and am excited to
help further Manning’s educational mission.
Licensed to Samir Mashlum <smashlum@gmail.com>
24.
xix
about this book
Reactin Action is about React, the library for building user interfaces on the web. It
covers the core concepts and APIs involved in building React applications. You’ll build
a sample social networking application with React over the course of the book. This
app will cover a variety of topics, ranging from adding dynamic data to rendering on
the server.
Audience
This book is written for people who want to learn React. It doesn’t matter if you’re a
software engineer, a VP of engineering, a CTO, a designer, an engineering manager,
a university or coding boot camp student, or someone who’s just curious about React.
Depending on what your needs are, you can focus on different parts of the book, too.
I cover React from a high level during the first part of the book and get more specific
and advanced as we go.
You’ll have a better experience reading the book if you have some basic familiarity
with JavaScript. This book uses a lot of JavaScript, but it isn’t about JavaScript. I don’t
cover fundamental concepts in JavaScript, although I do lightly touch on them if
they’re relevant to a discussion about React. You should be able to work through the
examples if you have a basic proficiency with JavaScript and understand how asyn-
chronous programming in JavaScript works.
React in Action also assumes that you know some of the basics of building a front-
end web application from a technology perspective—knowing about the basic browser
APIs will be helpful. You’ll work with things like the Fetch API to make network
Licensed to Samir Mashlum <smashlum@gmail.com>
25.
ABOUT THIS BOOK
xx
requests,set and get cookies, and work with user events (typing, clicks, and so on).
You’ll also interact heavily with libraries (although not too many!). Familiarity with
the basics of a modern frontend application will help you get the most out of this
book.
Fortunately, I’ve abstracted away all the complexity around tooling and the build
process that’s also a requisite part of building modern web applications. The source
code for the project includes all the necessary dependencies and build tools, so you
don’t have to understand, for example, how Webpack and Babel work in order to
enjoy this book. All in all, you should have at least a basic proficiency with JavaScript
and some frontend web application concepts to fully enjoy React in Action.
Roadmap
React in Action’s 13 chapters are divided into 3 parts.
Part 1, “Meet React,” introduces you to React. Chapter 1 covers core ideas of React
at a high level. It talks about some of the key points of React, shows how it might fit
into your development process, and looks at what React does and doesn’t do. Chapter
2 is the “show me the code” chapter. You’ll dive into React’s APIs and build a simple
comment box with React components.
Part 2, “Components and data in React,” is where you’ll start to go deeper with
React. You’ll see how data flows in React in chapter 3 and look at the component life-
cycle API and start building the Letters Social sample project in chapter 4. This proj-
ect will take us through the remainder of the book. Chapter 4 goes over setting up the
project from the application source code and explains how to work with it for the rest
of the book.
Chapters 5 through 9 are an even deeper dive into React. Chapter 5 covers work-
ing with forms and gives you another opportunity to work with data and data flow in
React. Chapter 6 follows in the same vein and builds on the work done in chapter 5 to
create a more complex React component for displaying maps.
Chapters 7 and 8 tackle routing, a crucial part of almost any modern frontend
application. You’ll build a router from scratch and get your app set up to handle mul-
tiple pages. You’ll keep going with routing in chapter 8 and integrate the Firebase
platform so you can authenticate users. Chapter 9 closes out part 3 by introducing
testing React apps and components.
Part 3, “React application architecture,” covers more advanced topics in React and
focuses especially on transitioning your application to use Redux. Chapters 10 and 11
introduce Redux, a state-management solution. Once your app is transitioned to use
Redux, we’ll explore server-side rendering in chapter 12. This chapter also covers
switching out your custom-built router for React Router. Chapter 13 briefly discusses
React Native, another React project that allows you to write JavaScript React apps for
mobile devices (iOS and Android).
Licensed to Samir Mashlum <smashlum@gmail.com>
26.
ABOUT THIS BOOKxxi
About the code
React in Action uses two main groups of source code. For the first two chapters, you’ll
work with code outside the project repository. You’ll be able to run these code samples
on Codesandbox.io, an online code playground. It takes care of bundling your code
and running it in real time, so you don’t have to worry about setting up a build process.
In chapter 4, you’ll get set up with the project source code. It’s available for down-
load at the book’s website, www.manning.com/books/react-in-action, and on GitHub
online at https:/
/github.com/react-in-action/letters-social, and the final result of the
project is live at https:/
/social.react.sh. Each chapter or range of chapters has its own
branch in Git, so you can easily switch into a later chapter or follow the progression of
the project throughout the book. The source code all lives on GitHub, so feel free to
ask questions on GitHub or on the book’s forum at https:/
/forums.manning.com/
forums/react-in-action.
The JavaScript for the app should all be formatted using Prettier (https:/
/
github.com/prettier/prettier), written using the most current ECMAScript specifica-
tion (which is ES2017 at time of writing). Prettier uses concepts, syntax, and methods
available in that specification. The project includes an ESLint configuration, but if
you prefer to modify it to suit your own needs, feel free.
Software and hardware requirements
React in Action doesn’t have any strict hardware requirements. You’re free to use any
type of computer (physical or a virtual provider like Cloud9 https:/
/c9.io), although I
won’t address inconsistencies caused by differences in development environments. If
these issues come up for individual packages, the repositories for those packages or
Stack Overflow (https:/
/stackoverflow.com) are the best place to seek help.
As for software, here are a few requirements and recommendations:
■ The build process for the sample project uses node.js (https:/
/nodejs.org), so
you’ll need to install the latest stable version. See chapter 4 for more on getting
set up with node.js.
■ You’ll also need a text editor and a web browser. I recommend something like
Visual Studio Code (https:/
/code.visualstudio.com), Atom (https:/
/atom.io), or
Sublime Text (www.sublimetext.com).
■ You’ll use Chrome as the main browser for the course of the book, especially its
developer tools. Download it at www.google.com/chrome.
Licensed to Samir Mashlum <smashlum@gmail.com>
27.
xxii
about the author
MarkTielens Thomas is a full-stack software engineer and
author. He and his wife live and work in southern California.
Mark enjoys tackling large-scale engineering problems and lead-
ing teams to deliver high-impact, high-value solutions. He loves
Jesus, good coffee, too many books, fast APIs, and beautiful sys-
tems. He writes for Manning and on his personal blog at https:/
/
ifelse.io.
Licensed to Samir Mashlum <smashlum@gmail.com>
28.
xxiii
about the coverillustration
The caption for the illustration on the cover of React in Action is “The Capitan Pasha,
Derya Bey, admiral of the Turkish navy.” The capitan pasha was a high-admiral with
supreme command of the navy of the Ottoman Empire. The illustration is taken from
a collection of costumes of the Ottoman Empire published on January 1, 1802, by
William Miller of Old Bond Street, London. The title page is missing from the collec-
tion, and we have been unable to track it down to date. The book’s table of contents
identifies the figures in both English and French, and each illustration bears the
names of two artists who worked on it, both of whom would no doubt be surprised to
find their art gracing the front cover of a computer programming book ... two hun-
dred years later.
The collection was purchased by a Manning editor at an antiquarian flea market in
the “Garage” on West 26th Street in Manhattan. The seller was an American based in
Ankara, Turkey, and the transaction took place just as he was packing up his stand for
the day. The Manning editor didn’t have on his person the substantial amount of cash
that was required for the purchase, and a credit card and check were both politely
turned down. With the seller flying back to Ankara that evening, the situation was get-
ting hopeless. What was the solution? It turned out to be nothing more than an old-
fashioned verbal agreement sealed with a handshake. The seller simply proposed that
the money be transferred to him by wire, and the editor walked out with the bank
information on a piece of paper and the portfolio of images under his arm. Needless
to say, we transferred the funds the next day, and we remain grateful and impressed by
Licensed to Samir Mashlum <smashlum@gmail.com>
29.
ABOUT THE COVERILLUSTRATION
xxiv
this unknown person’s trust in one of us. It recalls something that might have hap-
pened a long time ago.
We at Manning celebrate the inventiveness, the initiative, and, yes, the fun of the
computer business with book covers based on the rich diversity of regional life of two
centuries ago, brought back to life by the pictures from this collection.
Licensed to Samir Mashlum <smashlum@gmail.com>
30.
Part 1
Meet React
Ifyou’ve worked on frontend JavaScript applications in the past two years,
you’ve probably heard of React. You might have heard of it even if you’re just start-
ing out building user interfaces. Even if you’re hearing about React for the first
time in this book, I’ve still got you covered: there are many hugely popular appli-
cations that use React. If you use Facebook, watch Netflix, or learn about com-
puter science through Khan Academy, you’ve used an application built with React.
React is a library for building user interfaces. It was created by engineers at
Facebook and since its release has made waves in the JavaScript communities. It’s
gained in popularity over the past few years and is the tool of choice for many
teams and engineers building dynamic user interfaces. In fact, the combination of
React’s API, mental model, and robust community have led to the development of
React for other platforms, including mobile and even virtual reality.
In this book, you’ll explore React and see why it’s been such a successful and
useful open source project. In part 1, you’ll start with the basics of React and learn
them from the ground up. Because the tooling involved in building robust JavaS-
cript UI applications can be incredibly complex, we’ll avoid getting bogged down
in tools and focus on learning the ins and outs of the React API. We’ll also avoid
“magic” and work toward a concrete understanding of React and how it works.
In chapter 1, you’ll learn about React at a high level. We’ll cover some
important ideas like components, the virtual DOM, and some of the tradeoffs of
React. In chapter 2, you’ll take a whirlwind tour through React’s APIs and build
a simple comment-box component to get your hands dirty with React.
Licensed to Samir Mashlum <smashlum@gmail.com>
3
Meet React
If youwork as a web engineer in the tech industry, chances are you’ve heard of
React. Maybe it was somewhere online like Twitter or Reddit. Maybe a friend or col-
league mentioned it to you or you heard a talk about it at a meetup. Wherever it
was, I bet that what you heard was probably either glowing or a bit skeptical. Most
people tend to have a strong opinion about technologies like React. Influential and
impactful technologies tend to generate that kind of response. For these technolo-
gies, often a smaller number of people initially “get it” before the technology
catches on and moves to a broader audience. React started this way, but now enjoys
immense popularity and use in the web engineering world. And it’s popular for
This chapter covers
Introducing React
Some of React’s high-level concepts and
paradigms
The virtual DOM
Components in React
React for teams
Tradeoffs of using React
Licensed to Samir Mashlum <smashlum@gmail.com>
33.
4 CHAPTER 1Meet React
good reason: it has a lot to offer and can reinvigorate, renew, or even transform how
you think about and build user interfaces.
1.1 Meet React
React is a JavaScript library for building user interfaces across a variety of platforms.
React gives you a powerful mental model to work with and helps you build user inter-
faces in a declarative and component-driven way. We’ll unpack these ideas and much
more over the course of the book, but that’s what React is in the broadest, briefest sense.
Where does React fit into the broader world of web engineering? You’ll often hear
React talked about in the same space as projects like Vue, Preact, Angular, Ember, Web-
pack, Redux and other well-known JavaScript libraries and frameworks. React is often a
major part of front-end applications and shares similar features with the other libraries
and frameworks just mentioned. In fact, many popular front-end technologies are more
like React in subtle ways now than in the past. There was a time when React’s approach
was novel, but other technologies have since been influenced by React’s component-
driven, declarative approach. React continues to maintain a spirit of rethinking estab-
lished best practices, with the main goal being providing developers with an expressive
mental model and a performant technology to build UI applications.
What makes React’s mental model powerful? It draws on deep areas of computer
science and software engineering techniques. React’s mental model draws broadly on
functional and object-oriented programming concepts and focuses on components as
primary units for building with. In React applications, you create interfaces from com-
ponents. React’s rendering system manages these components and keeps the applica-
tion view in sync for you. Components often correspond to aspects of the user
interface, like datepickers, headers, navbars, and others, but they can also take
responsibility for things like client-side routing, data formatting, styling, and other
responsibilities of a client-side application.
Components in React should be easy to think about and integrate with other React
components; they follow a predictable lifecycle, can maintain their own internal state,
and work with “regular old JavaScript.” We’ll dive into these ideas over the course of
the rest of the book, but we can look at them at a high level right now. Figure 1.1 gives
you an overview of the major ingredients that go into a React application. Let’s look at
each part briefly:
Components—Encapsulated units of functionality that are the primary unit in
React. They utilize data (properties and state) to render your UI as output; we’ll
explore how React components work with data later in chapter 2 onward. Cer-
tain types of React components also provide a set of lifecycle methods that you
can hook into. The rendering process (outputting and updating a UI based on
your data) is predictable in React, and your components can hook into it using
React’s APIs.
React libraries—React uses a set of core libraries. The core React library works
with the react-dom and react-native libraries and is focused on component
Licensed to Samir Mashlum <smashlum@gmail.com>
34.
5
Meet React
specification anddefinition. It allows you to build a tree of components that a
renderer for the browser or another platform can use. react-dom is one such
renderer and is aimed at browser environments and server-side rendering. The
React Native libraries focus on native platforms and let you create React appli-
cations for iOS, Android, and other platforms.
Components
Other JavaScript
(other modules, custom methods)
<Component
display
userID={12}>
<OtherComponent/>
<Component>
{"user": {name: "Mark"}}
componentWillMount
componentDidMount
componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
componentDidUpdate
componentWillUnmount
Application
Application code (components, styles, utilities, business logic)
React
React DOM / React-
Native / React VR
Other libraries
Native devices
(iOS, Android)
VR Devices
(React VR)
Server
(node.js)
Desktop &
Mobile
Props
Internal component state Lifecycle methods
Target environments/platforms
Figure 1.1 React allows you to create user interfaces from components.
Components maintain their own state, are written in and work with “vanilla”
JavaScript, and inherit a number of helpful APIs from React. Most React apps
are written for browser-based environments, but can also be used in native
environments like iOS and Android. For more about React Native, see Nader
Dabit’s React Native in Action, also available from Manning.
Licensed to Samir Mashlum <smashlum@gmail.com>
35.
6 CHAPTER 1Meet React
Third-party libraries—React doesn’t come with tools for data modeling, HTTP
calls, styling libraries, or other common aspects of a front-end application. This
leaves you free to use additional code, modules, or other tools you prefer in
your application. And even though these common technologies don’t come
bundled with React, the broader ecosystem around React is full of incredibly
useful libraries. In this book, we’ll use a few of these libraries and devote chap-
ters 10 and 11 to looking at Redux, a library for state management.
Running a React application—Your React application runs on the platform you’re
building for. This book focuses on the web platform and builds a browser and
server-based application, but other projects like React Native and React VR
open the possibility of your app running on other platforms.
We’ll spend lots of time exploring the ins and outs of React in this book, but you
may have a few questions before getting started. Is React something for you? Who
else is using React? What are some of the tradeoffs of using React or not? These are
important questions about a new technology that you’ll want answered before
adopting it.
1.1.1 Who this book is for
This book is for anyone who’s working on or interested in building user interfaces.
Really, it’s is for anyone who’s curious about React, even if you don’t work in UI engi-
neering. You’ll get the most out of this book if you have some experience with using
JavaScript to build front-end applications.
You can learn how to build applications with React as long as you know the basics
of JavaScript and have some experience building web applications. I don’t cover the
fundamentals of JavaScript in this book. Topics like prototypal inheritance, ES2015+
code, type coercion, syntax, keywords, asynchronous coding patterns like async/await,
and other fundamental topics are beyond the scope of this book. I do lightly cover
anything that’s especially pertinent to React but don’t dive deep into JavaScript as a
language.
This doesn’t mean you can’t learn React or won’t get anything from this book if
you don’t know JavaScript. But you’ll get much more if you take the time to learn
JavaScript first. Charging ahead without a working knowledge of JavaScript will make
things more difficult. You might run into situations where things might seem like
“magic” to you—things will work, but you won’t understand why. This usually hurts
rather than helps you as a developer, so ... last warning: get comfortable with the
basics of JavaScript before learning React. It’s a wonderfully expressive and flexible
language. You’ll love it!
You may already know JavaScript well and may have even dabbled in React before.
This wouldn’t be too surprising given how popular React has become. If this is you,
you’ll be able to gain a deeper understanding of some of the core concepts of React.
But I don’t cover highly specific topics you may be looking for if you’ve been working
Licensed to Samir Mashlum <smashlum@gmail.com>
36.
7
Meet React
with Reactfor a while. For those, see other React-related Manning titles like React
Native in Action.
You may not fit into either group and may want a high-level overview of React. This
book is for you, too. You’ll learn the fundamental concepts of React and you’ll have
access to a sample application written in React—check out the running app at
https:/
/social.react.sh. You’ll be able to see the basics of building a React application
in practice and how it might be suited to your team or next project.
1.1.2 A note on tooling
If you’ve worked extensively on front-end applications in the past few years, you won’t
be surprised by the fact that the tooling around applications has become as much a
part of the development process as frameworks and libraries themselves. You’re likely
using something like Webpack, Babel, or other tools in your applications today. Where
do these and other tools fit into this book, and what you need to know?
You don’t need to be a master of Webpack, Babel, or other tools to enjoy and read
this book. The sample application I’ve created utilizes a handful of important tools,
and you can feel free to read through the configuration code for these in the sample
application, but I don’t cover these tools in depth in this book. Tooling changes
quickly, and more importantly, it would be well outside the scope of this book to cover
these topics in depth. I’ll be sure to note anywhere tooling is relevant to our discus-
sion, but besides that I’ll avoid covering it.
I also feel that tooling can be a distraction when learning a new technology like
React. You’re already trying to get your head around a new set of concepts and para-
digms—why clutter that with learning complex tooling too? That’s why chapter 2
focuses on learning "vanilla” React first before moving on to features like JSX and
JavaScript language features that require build tools. The one area of tooling that
you’ll need to be familiar with is npm. npm is the package management tool for Java-
Script, and you’ll use it to install dependencies for your project and run project com-
mands from the command line. It’s likely you’re already familiar with npm, but if not,
don’t let that dissuade you from reading the book. You only need the most basic termi-
nal and npm skills to go forward. You can learn about npm at https:/
/docs.npmjs
.com/getting-started/what-is-npm.
1.1.3 Who uses React?
When it comes to open source software, who is (and who isn’t) using it is more than just
a matter of popularity. It affects the experience you’ll have working with the technology
(including availability of support, documentation, and security fixes), the level of innova-
tion in the community, and the potential lifetime of a certain tool. It’s generally more
fun, easier, and overall a smoother experience to work with tools that have a vibrant com-
munity, a robust ecosystem, and a diversity of contributor experience and background.
React started as a small project but now has broad popularity and a vibrant com-
munity. No community is perfect, and React’s isn’t either, but as far as open source
Licensed to Samir Mashlum <smashlum@gmail.com>
37.
8 CHAPTER 1Meet React
communities go, it has many important ingredients for success. What’s more, the
React community also includes smaller subsets of other open source communities.
This can be daunting because the ecosystem can seem vast, but it also makes the
community robust and diverse. Figure 1.2 shows a map of the React ecosystem. I
mention various libraries and projects throughout the course of the book, but if
you’re curious to learn more about the React ecosystem, I’ve put together a guide at
https:/
/ifelse.io/react-ecosystem. I’ll keep this updated over time and ensure it evolves
as the ecosystem does.
The primary way you might interact with React is probably in open source, but you
likely use apps built with it every day. Many companies use React in different and
exciting ways. Here are a few of the companies using React to power their products:
Portal to Preact Mirror World
JavaScript Ocean
Bay of Jest
The United State(s)
of Management
Fluxville
Reduxopolis
Mobxton
JavaScript
Fatigue Cove
Upper GraphQLton
Relay Town
Utilitopia
The Monadic
Kingdom of FP
Immutable City
Tutorialandia
React VR
WebAssembly
Future Reconciler Research
Uncharted territory
Tooling Town
Babel Transpilation
Institutes
The Great
Bundle Forges
CSS Plains
Styled Components
CSS Modules
Glamor(ous)
Aphrodite
Styletron
Radium forest
Downtown React
TC39 Embassy
Center for Twitter
Thought-leadership React High Council
Conference
Center
Reconciler
Research
Center
Large DOM
Reconciler
Central Github
Repository
Serverland
The Testing Narrows
Enzyme
Bend
Component
Canyon
React Native
Bridge
The React Ecosystem
Copyright Mark Thomas 2017
Figure 1.2 A map of the React ecosystem is diverse—even more so than I can represent here. If you’d like to
learn more, check out my guide at https:/
/ifelse.io/react-ecosystem, which will help you find your way in the
React ecosystem when starting out.
Licensed to Samir Mashlum <smashlum@gmail.com>
38.
9
What does Reactnot do?
These companies aren’t blindly following the trends of the JavaScript community.
They have exceptional engineering demands that impact a huge number of users and
must deliver products on hard deadlines. Someone saying, “I heard React was good;
we should React-ify everything!” won’t fly with managers or other engineers. Compa-
nies and developers want good tools that help them think better and move quickly so
they can build high-impact, scalable, and reliable applications.
1.2 What does React not do?
So far, I’ve been talking about React at a high-level: who uses it, who this book is for,
and so on. My primary goals in writing this book are to teach you how to build applica-
tions with React and empower you as an engineer. React isn’t perfect, but it’s genu-
inely been a pleasure to work with, and I’ve seen teams do great things with it. I love
writing about it, building with it, hearing talks about it at conferences, and engaging
in the occasional spirited debate about this or that pattern.
But I would be doing you a disservice if I didn’t talk about some of the downsides
of React and describe what it doesn’t do. Understanding what something can’t do is as
important as understanding what it can do. Why? The best engineering decisions and
thinking usually happen in terms of tradeoffs instead of opinions or absolutes (“React
is fundamentally better than tool X because I like it more”). On the former point:
you’re probably not dealing with two totally different technologies (COBOL versus
JavaScript); hopefully you’re not even considering technologies that are fundamentally
unsuited to the task at hand. And to the latter point: building great projects and solv-
ing engineering challenges should never be about opinions. It’s not that people’s
opinions don’t matter—that’s certainly not true—it’s that opinions don’t make things
work well or at all.
■ Facebook ■ Asana
■ Netflix ■ ESPN
■ New Relic ■ Walmart
■ Uber ■ Venmo
■ Wealthfront ■ Codecademy
■ Heroku ■ Atlassian
■ PayPal ■ Asana
■ BBC ■ Airbnb
■ Microsoft ■ Khan Academy
■ NFL ■ FloQast
■ And more!
Licensed to Samir Mashlum <smashlum@gmail.com>
39.
10 CHAPTER 1Meet React
1.2.1 Tradeoffs of React
If tradeoffs are the bread and butter of good software evaluation and discussion, what
tradeoffs are there with React? First, React is sometimes called just the view. This can be
misconstrued or misunderstood because it can lead you to think React is just a tem-
plating system like Handlebars or Pug (née Jade) or that it has to be part of an MVC
(model-view-controller) architecture. Neither is true. React can be both of those
things, but it can be much more. To make things easier, I’ll describe React more in
terms of what it is than what it’s not (“just the view,” for example). React is a declarative,
component-based library for building user interfaces that works on a variety of platforms:
web, native, mobile, server, desktop, and even on virtual reality platforms going for-
ward (React VR).
This leads to our first tradeoff: React is primarily concerned with the view aspects
of UI. This means it’s not built to do many of the jobs of a more comprehensive frame-
work or library. A quick comparison to something like Angular might help drive this
point home. In its most recent major release, Angular has much more in common
with React than it previously did in terms of concepts and design, but in other ways it
covers much more territory than React. Angular includes opinionated solutions for
the following:
HTTP calls
Form building and validation
Routing
String and number formatting
Internationalization
Dependency injection
Basic data modeling primitives
Custom testing framework (although this isn’t as important a distinction as the
other areas)
Service workers included by default (a worker-style approach to executing
JavaScript)
That’s a lot, and in my experience there are generally two ways people tend to react1
to all these features coming with a framework. Either it’s along the lines of “Wow, I
don’t have to deal with all those myself” or it’s “Wow, I don’t get to choose how I do
anything.” The upside of frameworks like Angular, Ember, and the like is that there’s
usually a well-defined way to do things. For example, routing in Angular is done with
the built-in Angular Router, HTTP tasks are all done with the built-in HTTP routines,
and so on.
There’s nothing fundamentally wrong with this approach. I’ve worked on teams
where we used technologies like this and I’ve worked on teams where we went the
1
Pun not intended but, hey, it’s a book about React, so there it is.
Licensed to Samir Mashlum <smashlum@gmail.com>
40.
11
What does Reactnot do?
more flexible direction and chose technologies that “did one thing well.” We did great
work with both kinds of technologies, and they served their purposes well. My per-
sonal preference is toward the choose-your-own, does-one-thing-well approach, but
that’s really neither here nor there; it’s all about tradeoffs. React doesn’t come with
opinionated solutions for HTTP, routing, data modeling (although it certainly has
opinions about data flow in your views, which we’ll get to), or other things you might
see in something like Angular. If your team sees this as something you absolutely can’t
do without in a singular framework, React might not be your best choice. But in my
experience, most teams want the flexibility of React coupled with the mental model
and intuitive APIs that it brings.
One upside to the flexible approach of React is that you’re free to pick the best
tools for the job. Don’t like the way X HTTP library works? No problem—swap it out
for something else. Prefer to do forms in a different way? Implement it, no problem.
React provides you with a set of powerful primitives to work with. To be fair, other
frameworks like Angular will usually allow you to swap things out too, but the de
facto and community-backed way of doing things will usually be whatever is built-in
and included.
The obvious downside to having more freedom is that if you’re used to a more
comprehensive framework like Angular or Ember, you’ll need to either come up with
or find your own solution for different areas of your application. This can be a good
thing or a bad thing, depending on factors like developer experience on your team,
engineering management preferences, and other factors specific to your situation.
There are plenty of good arguments for the one-size-fits-all as well as the does-one-
thing-well approaches. I tend to be more convinced by the approach that lets you
adapt and make flexible, case-by-case decisions about tooling over time in a way that
entrusts engineering teams with the responsibility to determine or create the right
tools. There’s also the incredibly broader JavaScript ecosystem to consider—you’ll be
hard-pressed to find nothing aimed at a problem you’re solving. But at the end of the
day, the fact remains that excellent, high-impact teams use both sorts of approaches
(sometimes at the same time!) to build out their products.
I’d be remiss if I didn’t mention lock-in before moving on. It’s an unavoidable fact
that JavaScript frameworks are rarely truly interoperable; you can’t usually have an
app that’s part Angular, part Ember, part Backbone, and part React, at least not with-
out segmenting off each part or tightly controlling how they interact. It doesn’t usu-
ally make sense to put yourself in that sort of situation when you can avoid it. You
usually go with one and maybe temporarily, at most, two primary frameworks for a par-
ticular application.
But what happens when you need to change? If you use a tool with wide-ranging
responsibilities like Angular, migrating your app is likely going to be a complete
rewrite due to the deep idiomatic integration of your framework. You can rewrite
smaller parts of the application, but you can’t just swap out a few functions and expect
everything to work. This is an area where React can shine. It employs relatively few
Licensed to Samir Mashlum <smashlum@gmail.com>
41.
12 CHAPTER 1Meet React
“magic” idioms. That doesn’t mean it makes migration painless, but it does help you
to potentially forgo incurring the cost of a tightly integrated framework like Angular if
you migrate to or from it.
Another tradeoff you make when choosing React is that it’s primarily developed
and built by Facebook and is meant to serve the UI needs of Facebook. You might
have a hard time working with React if your application is fundamentally different
than the UI needs of Facebook’s apps. Fortunately, most modern web apps are in
React’s technological wheelhouse, but there are certainly apps that aren’t. These
might also include apps that don’t work within the conventional UI paradigms of
modern web apps or apps that have very specific performance needs (such as a high-
speed stock ticker). Yet even these can often be addressed with React, though some sit-
uations require more-specific technologies.
One last tradeoff we should discuss is React’s implementation and design. Baked
into the core of React are systems that handle updating the UI for you when the data
in your components change. They execute changes that you can hook into using cer-
tain methods called lifecycle methods. I cover these extensively in later chapters. React’s
systems that handle updating your UI make it much easier to focus on building modu-
lar, robust components that your application can use. The way React abstracts away
most of the work of keeping a UI up-to-date with data is a big part of why developers
enjoy working with it so much and why it’s a powerful primitive in your hands. But it
shouldn’t be assumed that there are no downsides or tradeoffs made with respect to
the “engines” that power the technology.
React is an abstraction, so the costs of it being an abstraction still remain. You
don’t get as much visibility into the system you’re using because it’s built in a particu-
lar way and exposed through an API. This also means you’ll need to build your UI in
an idiomatically React way. Fortunately, React’s APIs provide “escape hatches” that let
you drop down into lower levels of abstraction. You can still use other tools like
jQuery, but you’ll need to use them in a React-compatible way. This again is a tradeoff:
a simpler mental model at the cost of not being able to do absolutely everything how
you’d like.
Not only do you lose some visibility to the underlying system, you also buy into
the way that React does things. This tends to impact a narrower slice of your applica-
tion stack (only views instead of data, special form-building systems, data modeling,
and so on), but it affects it nonetheless. My hope is that you’ll see that the benefits
of React far outweigh the cost of learning it and that the tradeoffs you make when
using it generally leave you in a much better place as a developer. But it would be
disingenuous for me to pretend that React will magically solve all your engineering
challenges.
1.3 The virtual DOM
We’ve talked a little bit about some of the high-level features of React. I’ve posited that
it can help you and your team become better at creating user interfaces and that part
Licensed to Samir Mashlum <smashlum@gmail.com>
42.
13
The virtual DOM
ofthis is due to the mental model and APIs that React provides. What’s behind all
that? A major theme in React is a drive to simplify otherwise complex tasks and
abstract unnecessary complexity away from the developer. React tries to do just
enough to be performant while freeing you up to think about other aspects of your
application. One of the main ways it does that is by encouraging you to be declarative
instead of imperative. You get to declare how your components should behave and look
under different states, and React’s internal machinery handles the complexity of man-
aging updates, updating the UI to reflect changes, and so on.
One of the major pieces of technology driving this is the virtual DOM. A virtual
DOM is a data structure or collection of data structures that mimics or mirrors the
Document Object Model that exists in browsers. I say a virtual DOM because other
frameworks such as Ember employ their own implementation of a similar technology.
In general, a virtual DOM will serve as an intermediate layer between the application
code and the browser DOM. The virtual DOM allows the complexity of change detec-
tion and management to be hidden from the developer and moved to a specialized
layer of abstraction. In the next sections, we’ll look from a high level at how this works
in React. Figure 1.3 shows a simplified overview of the DOM and virtual DOM rela-
tionship that we’ll explore shortly.
1.3.1 The DOM
The best way to ensure that we understand React’s virtual DOM is to start by checking
our understanding of the DOM. If you already feel you have a deep understanding of
JavaScript Interpreter
Browser
Browser “native” engine
Actual DOM
Virtual DOM
Synthetic
Event system
Optimized
updates
Input,
events,
status
Figure 1.3 The DOM and virtual DOM. React’s virtual DOM handles change detection in data as
well as translating browser events into events that React components can understand and react
to. React’s virtual DOM also aims to optimize changes made to the DOM for the sake of
performance.
Licensed to Samir Mashlum <smashlum@gmail.com>
43.
14 CHAPTER 1Meet React
the DOM, feel free to move ahead. But if not, let’s start with an important question:
what is the DOM? The DOM, or Document Object Model, is a programming interface
that allows your JavaScript programs to interact with different types of documents
(HTML, XML, and SVG). There are standards-driven specifications for it, which
means that a public working group has created a standard set of features it should
have and ways it should behave. Although other implementations exist, the DOM is
mostly synonymous with web browsers like Chrome, Firefox, and Edge.
The DOM provides a structured way of accessing, storing, and manipulating differ-
ent parts of a document. At a high level, the DOM is a tree structure that reflects the
hierarchy of an XML document. This tree structure is comprised of sub-trees that are
in turn made of nodes. You’ll probably know these as the divs and other elements that
make up your web pages and applications.
You’ve probably used the DOM API before—but you may not have known you
were using it. Whenever you use a method in JavaScript that accesses, modifies, or
stores information related to something in an HTML document, you’re almost cer-
tainly using the DOM or its related APIs (see https:/
/developer.mozilla.org/en-
US/docs/Web/API for more on web APIs). This means that not all the methods
you’ve used in JavaScript are necessarily part of the JavaScript language itself (docu-
ment.findElemenyById, querySelectorAll, alert, and so on). They’re part of the
bigger collection of web APIs—the DOM and other APIs that go into a browser—that
allow you to interact with documents. Figure 1.4 shows a simplified version of the
DOM tree structure you’ve probably seen in your web pages.
Common methods or properties you may have used to update or query a web page
might include getElementById, parent.appendChild, querySelectorAll, innerHTML,
Element:
<title>
Element
<head>
innerText:
“React”
Document
Root element
<html>
Element:
<a>
innerText:
“React is cool”
Element:
<h1>
innerText:
“Welcome”
Element
<body>
Figure 1.4 Here’s a simple version of the DOM tree structure, using elements
you’re probably familiar with. The DOM API that’s exposed to JavaScript lets
you performs operations on these elements in the tree.
Licensed to Samir Mashlum <smashlum@gmail.com>
44.
15
The virtual DOM
andothers. These are all provided by the host environment (in this case, the browser)
and allow JavaScript to interact with the DOM. Without this ability, we’d have far less
interesting web apps to use and perhaps no books about React to write!
Interacting with the DOM is usually straightforward but can get complicated in the
context of a large web application. Fortunately, we don’t often need to directly inter-
act with the DOM when building applications with React—we mostly leave that to
React. There are cases when we want to reach out past the virtual DOM and interact
with the DOM directly, and we’ll cover those in future chapters.
1.3.2 The virtual DOM
The web APIs in browsers let us interact with web documents with JavaScript via the
DOM. But if we can already do this, why do we need something else in between? I
want to first state that React’s implementation of a virtual DOM doesn’t mean that the
regular web APIs are bad or inferior to React. Without them, React can’t work. There
are, however, certain pain points of working directly with the DOM in larger web
applications. Generally, these pain points arise in the area of change detection. When
data changes, we want to update the UI to reflect that. Doing that in a way that’s effi-
cient and easy to think about can be difficult, so React aims to solve that problem.
Part of the reason for that problem is the way browsers handle interactions with
the DOM. When a DOM element is accessed, modified, or created, the browser is
often performing a query across a structured tree to find a given element. That’s just
to access an element, which is usually only the first part of an update. More often than
not, it may have to reperform layout, sizing, and other actions as part of a mutation—
all of which can tend to be computationally expensive. A virtual DOM won’t get you
around this, but it can help updates to the DOM be optimized to account for these
constraints.
When creating and managing a sizeable application that deals with data that
changes over time, many changes to the DOM may be required, and often these
changes can conflict or are done in a less-than-optimal way. That can result in an
overly complicated system that’s difficult for engineers to work on and likely a subpar
experience for users—lose-lose. Thus performance is another key consideration in
React’s design and implementation. Implementing a virtual DOM helps address this,
but it should be noted that it’s designed to be just “fast enough.” A robust API, simple
mental model, and other things like cross-browser compatibility end up being more
important outcomes of React’s virtual DOM than an extreme focus on performance.
The reason I make this point is that you may hear the virtual DOM talked about as a
sort of silver bullet for performance. It is performant, but it’s no magic performance
bullet, and at the end of the day, many of its other benefits are more important for
working with React.
Licensed to Samir Mashlum <smashlum@gmail.com>
If he wereaware of expecting anything in return, from a poor
Italian, it was the usual ecstatic thankful benediction of poor Italians
in like luck. Once he had lived among them on their own soil; he
knew the simple-hearted, engaging, vagabond breed through and
through. But this specimen of it flushed and scowled, while trying to
seem courteous; and his would-be benefactor was puzzled. As they
stood opposite, they were of equal height; for the younger had
drawn himself up a good inch.
"I am afraid you are proud. You have picked that up in New
England."
Rodolfo answered resentfully: "Sir, I have the blood of New England
also, and it is for me the destiny to earn my money, most of all after
what I promise to the beautiful Anne."
As he said it, warming thus into his very self, the eyes of Openshaw,
watching him, were dazzled, as one may be who crosses an alcove
towards a door in plain sight, and finds that seeming door a mirror. A
little alarum-bell rang in his brain. He shuddered, for all the forces
within him were rallying together: triumph, hate, revenge, deadly
delight; things he had not known were possible to him swarmed into
his spirit with a clang. He recognized, at a stroke, that this vagrant
youth, this common workman, looking at him with no smile now,
bore a violent resemblance to himself. He searched for details,
lightning-quick, and devouringly. Yes! there were the dark, fine,
pendulous hair, the small, close ear, the strong nose and jaw, even
the large, slender hand toil had hardly scarred, the back of it smooth
and hard as veined marble; how like the Openshaw hand, plain in
the old Lely portrait, plainer yet in the Stuarts, on the melancholy
walls of his own home! And what followed? The voice, significant,
prophetic, of the demon of self-preservation in his ear: "This may be
the man who killed George Wheeling. This must be the man.
Impeach him; clear yourself!" Openshaw, in his calmer mood, a few
moments back, had measured the character before him. Whatever
else it was, it was not astute. He foresaw no trouble in worming the
secret out of him.
47.
"Very well," hereplied, as if æons on æons of thought had not
passed since he spoke last. "I will take the gold-piece back, on your
own condition: I will see that you earn it. Have you business on
hand?"
"Oh, no. The venerable butcher, the fever kills him; we bury him,
and locka the door for all day." Rodolfo was sullen yet.
"Then, will you kindly go into the square, buy me cheese, pilot
bread, two quart bottles of Sauterne, and two glasses, and return by
way of Daniels Street? I shall be waiting at the landing. I should like
to hire a boat for an hour, and have you row me up river. Will you do
so?"
The lad hesitated. Finally, touched, or put upon his mettle by a
seeming confidence, he set out, with the greenback in his pocket
which Mr. Openshaw had given him. The latter, at this pause in their
colloquy, was made aware that he was suffering keenly. He had
exceeding self-control; his successes in life had sprung from it. But
every mastered nerve in his body, having already undergone so
much, and having so much to undergo, was humming like a beehive.
He could not stand still. He wandered about, meeting few
pedestrians, across Water Street, up Manning Street to Puddle Dock
with its liberty pole, and again past the graveyard, lingering
wherever he could command a view of the broad glorious
anchorage, tragic with the exposed ribs of rotting ships. Into the
happier neighborhoods near, he would not penetrate; this one had
been happy too, when he was a child. There he saw but visions of
greatness gone, of comfort broken, and an hour ago, could have laid
his cheek to the old flaggings, and wept. But he had now a terrible
just purpose, and for that he must save his strength.
He was at the landing later than Rodolfo, who sat in a white wherry
ballasted with his purchases, the oars already in hand. Openshaw
rested his cane on the gunwale, and stepped quietly into the stern;
they backed out of the cramped spaces, and shot away. The surface
of the harbor was dimpling, little by little, with the great hidden
swirls of the turning tide; deceptively glassy between its deflected
48.
banks, it gleamedlike the thin ice which forms in November, and
over which boys send pebble after pebble, and laugh to hear them
chirruping. But Rodolfo had learned long since how to cajole the
fierce Piscataqua; and tacking artfully by St. John's Point, he labored
through the end arch of the great bridge, and gained the blue
highway beyond. A train thundered overhead. Two women in the
footpath, leaning over the rail, stared fixedly at the little boat, and
from one sensitive face to the other, and again at their contrasted
attire. They were Rodolfo's neighbors, and pleased that he had fallen
in with a gentleman.
The cruisers were not back within the hour, nor within three hours.
The whole world was to change strangely for them both, meanwhile.
The order of what Langdon Openshaw had intended to say and do
came to naught, because what happens to happen is lord over the
strongest human will. He had prepared his cunning questionings, as
if to force his own fate, forgetting that the aggregation of outer
circumstance which we call fate is itself an irresistible vortex; the
trapper, and not the trapped. Up stream, by Frank's Fort, under a
sapphire sky, while as yet little had been said, he found that his
watch had run down, and he asked for the correct time. Rodolfo set
him right from a cheap timepiece. As he handled it, there appeared,
linked to the guard, an artistic bit of bronze, a tiny Renaissance
figure, with bow and hound, the blown draperies minutely fair.
Openshaw saw it, and the whole universe was not so manifest to
him as that small ominous curio within it.
"The Diana! On your soul, where, how, did you get that?" It was
familiar to him; he knew it, though he had not seen it for more than
a score of years. The rower dropped it back into his breast,
definitely.
"It is mine, and dear to me. My mother who gave it, she is dead."
"Did you say your mother's name was Potenza? Was it Agata
Potenza? Agata Boldoni once?"
"Yes."
49.
There was athronging pause.
"When did she die?"
"It was sixa years ago; I proceed to America."
"Have you brothers and sisters?"
"I have, in Italy, twin brothers, older; their lame-a father, Niccola
Potenza, live with them. But he is notta mine."
Quick, loud, sure, the queries and the answers fell, like the hammer-
strokes of a coffin in the making.
"Your father was—?"
"How can I know? They tell me he was vera handsome, vera rich,
and from this America. Malfattore! He steal away, and I am born
after; and she see him not in her life, I see him not in mine."
The crew had apparently hurt the passenger, for the latter heaved
against the thwarts.
"Once more. Was your mother ever married to your father?"
Rodolfo knit his brows, and set his teeth. "No."
For a long, long time there was no sound but the little singing keel
on its joyous flight, and Openshaw's head was hidden in his hands.
Rodolfo, of his own vigorous accord, took the way of Dover Bridge,
across the noble inland bay, and branched up the shallowing Oyster.
There by the bank, in the stiller solitudes, he shipped his oars, and,
reaching forth, touched the bowed shoulder, not without
compassion.
"Illustrissimo, look up! Tell me." Then did Openshaw begin, steadily,
but hardly above his breath, intent the while on the image of his
own youth before him, as if from that only he might draw courage to
confess.
"I have a dear friend who, when he was no older than you are now,
went to Italy. He spent his best years in a delusion, for he thought
then he might become a great painter. His character, such as it was
50.
and is, turnedto the things of good report; he was an orphan, with
a competence; but he had had no home, and no moral training.
Being something of a recluse, he developed late and slowly. At a
time when the storm-clouds in most young men's lives are lifting, his
were surcharging themselves, and getting ready to burst. On his
thirtieth birthday, in Ferrara, he—"
"In Ferrara, yes!" broke the eager interruption.
"He persuaded another man's wife to run away with him. She was a
peasant, very young and innocent, with a sweet pensive Perugino
face; she had been his model, up to her marriage with Niccola
Potenza."
There was a sharp affirmative breath from the listener.
"Niccola Potenza was a cooper, with good prospects. He was
considered quite a match for the girl; but he turned out to be dull,
silent, and preoccupied. Little Agata was romantic; and her thoughts
ran easily back to my friend. The fault was, assuredly, all his. He
thought that he loved her, and so, indeed, he did; although he loved
better, alas, the adventure and the rebellion. At any rate, he took her
away boldly from her husband and her babes, and set up life in his
old studio, in Florence. The cooper, sworn to revenge himself, had
nearly hunted my friend down, when on Easter Day he fell from a
crowded and festooned inn-balcony, and broke his thigh. Somehow,
after that, his fury failed him; and he sank, under his misfortune,
into a sort of apathy. Things went wrong also with the lovers. Agata
kept only for a while her soft, joyous, docile ways, and then grew
restless and wretched, with the canker of a good heart spoiled,
which nothing on earth can cure. She would spend hours in the
chapel near by, her face covered, thinking and weeping; and then
she would go back to her little household tasks, and move about in
my friend's sight, her pale penitent face driving him wild more
effectually than any audible reproach could have done. Of course he
saw what was in her soul: the struggle between her foolish passion
for him, and mortal home-sickness for the inner peace which had
attended her old honorable life. He, on his part, resented the moral
51.
awakening in her,and stamped down both her conscience and his
own. Against the voice within which bade him, since he had done
her an irretrievable wrong, to take the legal burden of it upon
himself, and make her his wife in America, arose his tyrannous social
cowardice. He dared not; he had a depraved but intelligent dread of
discord and incongruities. And so, as many another man as weak
has done, he served his æsthetic sense, and threw honor to the
winds. He was never, I think, wilfully unkind to Agata; his selfishness
would seem to me now less diabolic had he tried to estrange her
from him. But as soon as their first apprehensive year together had
passed, without any talk on the subject, he left her. Before he took
his train, that night in May, my friend drew up a paper for poor
Agata's maintenance. The sum was small, but much more than she
had been accustomed to call her own. I know he had no forewarning
of—of his child; he provided for her alone." Mr. Openshaw was
speaking with some difficulty. "When were you born?"
"On the feast of San Stefano, the twenty-sixta of December,
eighteen hundred sixta-five."
Rodolfo had been listening under a strain keener than that of
physical deafness. The more nervously overwrought of the two at
this particular moment, he was likewise the more restrained. A
certain question was hot in his throat. Though he had not
understood all of Mr. Openshaw's melancholy monologue, he had
apprehended the heart of it only too well. But he said nothing
further.
A flock of pioneer blackbirds, in delirious chatter, were gathering
overhead for their autumn migration, darkening the narrow sky-
space with their circling wings. Openshaw looked up.
"Those birds go from pole to pole to find—what? So did he. His
youth was killed in him; and before long, nevertheless, he was
cheerful and active again, and courted by the world. He came home
to his own honest and normal life, and after a while he married. He
had no tidings of Agata, and had actually resolved once to try to find
her, when he heard what must have been a false report, that she
52.
had died; andhe did not doubt it, for he used to see her faithful
patient little face in all his dreams. From what I have learned of late,
I believe that he is most miserable, and near his own end. He does
not deserve to hear of her last days. But if by letting me know, you
can punish him through me, do not spare him. I will not, I promise
you."
Rodolfo sat in the boat, immovable, the thin leaves of the bowery
wild-grape flapping overhead, and flickering him with elfin light and
shade. "My mother," he began in a low voice, "did the best: the
grace of God was in her. Niccola was sick; the trade was gone, and
then was mucha poverty. With me in her amiable arms, she return
on the feet to Ferrara, and petition him; and, lo! the good cripple
man, he pardon. There us four in one family, we flourish. The
American money she could notta help, go among all till all are
grown; she die of the fever sixa year ago, with many candles and
masses for her soul; and because it is notta fit that my brothers
spend on me, I ask Niccola's blessing, and come to America. That is
the end."
Openshaw inquired presently, when he could do so: "Had you any
education, as a child? Can you read and write, Rodolfo?"
"No." He sat sheepishly for a moment, then seized his oars.
"How have you prospered over here? Have you been able to save a
little? You spoke of wishing to return."
Rodolfo quivered. "It musta be."
"Why so?" There was genuine tenderness in the two words.
"There is nothing of hope for me. I am in a greata fix. I leave, I go;
I cannot stay. I have a sin also. Only my beloved, she know how it
was I transgress, so thatta perhaps my guilt is not for eternity."
Openshaw laid the tip of his stick upon the rowlock, with authority.
"Do not start yet; let the boat drift. You must be hungry with this
long exercise. Pray pass me those things near you, and the wine;
and while you lunch, I hope you will be as frank with me, Rodolfo, as
53.
I have beenwith you.... I look upon it as a miracle of mercy that at
the eleventh hour we have found each other." He knew that the
young man's blazing black eyes were full upon him. "I can help you.
Only keep nothing back." He filled one of the glasses from the fizzing
bottle, and passed it. But it was struck aside, and the cry that
followed was so sincere it gave the rudeness dignity.
"Ah! No, no, no. Sir, I touch the spiritual drink no more till I die. I
vow to Anita mia, after the terrible night. For see! The evil ones,
companions, take me on a burst in a city notta this, Hartaford, and
thieve." His voice dropped under the excitement, like a file of
infantry under fire. "They thieve a banka; and I watch, in gin so
drunk as Bacco; and when the invisible man arise pugnacious, I
throttle him, and curse, and rolla him down to the cellar. He moan
and expire, so that we go down to thieva more; but the city she
hears, there is a sound, then a sound on top of him, and we fly, fly,
fly, this streeta, that streeta, till I come back awake to this
Portsmouth, and fall on my knee to Anne, and cry tears. Ah, my
sainta! she comfort me in charity, and talk to me, and keepa me
from the bad; and for penance I go vera dry always, not to be
damn. I tell it not to Niccola at home when I go; and I pray to go
soon, that the Statesa Prison notta hanga me."
Such is the equilibrium between the infinite and folly, that at this
juncture, as he recalled afterwards, Mr. Openshaw was eating his
cheese. He answered, marvelling at his own composure.
"I read about it in the newspapers. You are in great danger, my poor
boy. Now listen. There is a ship sailing for Genoa from New York
next Saturday; and on her I wish you to engage your passage. That
will give you a week to adjust your little affairs here; and you must,
moreover, see your excellent sweetheart, and persuade her to marry
you and go with you. Will you do that?"
Rodolfo opened his fine eyes very wide, and then closed them. "Oh,
voluptuous as it would be, I cannot. The Capitan he make Anne
deny me until I shall have many riches. She is a handmaid of
domestic service on Pleasanta Street; but the old one, he is proud
54.
for her, andwith the mosta reason in all the world. I shall coop with
thesea my brothers cooping always in Ferrara, and do my parta with
my soul. For bye-and-bye we make a marriage; and then she will be
content to live in the sympathetic Italy, where safeness is for me."
"But we mean to mend all that, Rodolfo. Your father, whom I know
very well, is growing old, and has a great deal of property with no
one to share it. The least he can do for you (I am sure he feels
that), is to put you out of the reach of want. He will not ruin you,
nor throw you into temptations of a kind other than those you have
undergone; for you are his son, and as such he must love you. But
he will hope to hear by next spring, that you have bought a farm
and vineyard, and that your kind kins-people at home, and your
wife, sometimes pray for him; yes, and for me. Trust me; we need
say no more about it. He will have it all settled by law as soon as he
is able, but certainly within a month." He passed his hand over his
hair, absently, and resumed. "You will go across the ocean now; and
if my friend lives, he may come to you; but he may not live, and he
may not come. It is his punishment not so much to lose you, or what
you might, after all, be to him, as to recognize that his awful breach
of duty has established between you what I may call, perhaps, in the
long run, an incompatibility." Poor Openshaw, on the rack of his own
candor, groaned aloud.
Once more they were crossing Greenland Bay, and the lone and
lovely miles seaward. Rodolfo crept up quietly to his strange
benefactor, who was absently gazing far away, so quietly that the
wherry moved not a muscle under him.
"It is you," he said. "The 'friend' is a made-up. I know. Padre, si!" He
threw his arms about Mr. Openshaw, his old hatred melted away,
and lay there on his knees like a little boy, sobbing, sobbing. "It is
for nothing at all," he explained with his endearing semblance of
good-breeding; "but the gentle goodaness of God. The beautiful
Anne,—O you musta see her, and letta yourself be thank in so
harmonious the voice of seventeen! she will taka me. Behold, I am
55.
so vera, verahappy." Quite overcome, he did not even raise his head
when he was spoken to.
"Am I forgiven, Rodolfo? Can you forgive me for your poor mother's
sake?"
For answer, the lad covered the hand he held with kisses of southern
fervor, and pressed into it the little delicate charm from his watch-
string.
At the touch of it, the tyranny of yesterday and to-morrow, and all
his suffering present and to come, departed from Openshaw. A
divine felicity began now to possess him; he was grateful, he was at
peace; whatever his retribution was to be, he embraced it, in spirit,
like a bride. In his revery, he seemed to stand before the everlasting
tribunal, with inscrutable truth on his lips: "Of this that was mine I
was heedless. Because of my heedlessness, Poverty and Ignorance
and Inferiority and Exile took him by the hand, and led him to the
pit. He is rescued from the worst; he will cling to the highest which
he sees, with an elected soul to help him; but what he might have
been he can never be. It was I that sowed; let it be mine to reap.
The indelible blood that is shed is on my hands, not on his. Visit Thy
wrath upon me, for here is it due. With body and soul, will, sense,
and understanding, from first to last, in every fibre of my being, I
affirm me accountable for this thing." To the tribunal on earth, its
magnate of unblemished reputation had no explanation to offer. He
foresaw only his arraignment, and the words with which to clinch it:
"Gentlemen of the jury, I plead guilty."
Rodolfo spoke first. "I am so glad I guess, I guess from the teara in
your eye, that time."
The tears welled up again as the other replied: "There is something
else you will never guess, thank God."
"No?"
"No, my boy."
56.
Rodolfo looked up,and smiled, without irrelevant curiosity. He was
too content, afloat there.
The Honorable Langdon Openshaw took charge of the tiller, the son
to whom he had twice given life still at his feet. With neither oar nor
sail the guided boat came home from the upper waters to the port,
in the mellowing afternoon, borne on the mighty ebb-tide of the
Piscataqua.
57.
THE PROVIDER.
Nora criedout: "'Tis so pretty to-day!" The barefooted children were
threading the slopes of Howth towards Raheny. Far-off, the city, with
its lights and stretches of glorified evening water, was lying there
lovely enough between the mountains and the sea. It was Nora's
tenth birthday, and, to please her, they had been on the march all
afternoon, their arms full of rock-born speedwell and primrose. "'Tis
so pretty!" echoed little Winny, with enthusiasm. But the boy looked
abroad without a smile. "'T'd be prettier when things is right," he
answered severely. Hughey was a man of culture; but his speech
was the soft slipshod of the south. The three trudged on in silence,
for Hughey was a personage to his small sisters; and Hughey in a
mood was to be respected. He, alas, had been in a mood too long.
He had carried Winny over the roughest places, and shown her
Ireland's Eye, and, alongshore, the fishing-nets and trawls; he had
given his one biscuit to be shared between them all; and lying in the
velvet sward by the Druid stone, he had told them all he knew of the
fairy-folk in their raths, for the seventieth time. But he was full of
sad and bitter brooding the while, thinking of his mother, his poor
mother, his precious mother, working too hard at home, for whom
there never seemed to be any birthdays or out-of-door pleasures.
Hugh was nearly twelve now, and mature as the eldest child must
always be among the poor. He could remember times in the county
Wexford, before his father, who was of kin to half the gentry in the
countryside, died; times when life had a very different outlook, and
when his peasant mother, with short skirts and her sleeves rolled up,
would go gayly between her great stone-flagged kitchen and the
well or the turkey-hen's nest under the blackthorn hedge, singing,
singing, like a lark. They had to leave that pleasant farm, and the
thatched roof which had sheltered them from their fate, and move
up to cloudier Dublin, to a stifling garret over a beer-shop; and it
58.
was a miserablechange. Malachi O'Kinsella, the cheerful thriftless
man, with his handsome bearing and his superfluous oratory, was
gone; and his Hughey was too young to be of service to those he
left behind. A fine monument, with Glory be to God on it, had to be
put up over him in the old churchyard, two years ago; and there had
been since the problem of schooling, feeding, and clothing Hughey,
Nora, and Winny. Then Rose, three years old, fell into a lime-kiln,
and was associated with the enforced luxury of a second funeral;
and Dan, the baby, born after his father's death, was sickly, and
therefore costly too; and now the rent had to be paid, and the
morrow thought of, on just nothing a week! All of which this Hugh,
with his acumen and quick sympathy, had found out. He worshipped
his mother, in his shy, abstinent Irish way; his heart was bursting for
her sake, though he but half knew it, with a sense of the mystery
and wrong-headedness of human society.
That April Tuesday night, when the wildflowers were in a big earthen
basin on the table, like streaks of moonlight and moon-shadow, and
the girls were in bed, Hughey blew out his candle, shut up his penny
Gulliver, and went over to the low chair in their one room, where his
mother was crooning Dan to sleep on her breast. It shocked him to
see how thin she was. Her age was but three-and-thirty; but it might
have been fifty. She wore a faded black gown, of decent aspect once
in a village pew; her thick eyelashes were burning wet. Outside and
far below, were the polluted narrow cross-streets, full of flaring
torches, and hucksters' hand-carts, and drunken voices; and beyond,
loomed the Gothic bulk of Saint Patrick's, not a star above it.
"Mother! 'tis not going to school any more Oi'll be." His tired,
unselfish mother swallowed a great sigh, but said nothing. "Oi'll
worruk for ye, mother; Oi'll be your man. Oi can do't."
There was another and a longer pause; and then Moira O'Kinsella
suddenly bent forward and kissed her first-born. Like all the
unlettered class in Ireland, she adored learning from afar, and
coveted it for her offspring. That he should give up his hope of
"talkin' Latin" touched her to the quick. "God love ye, Hughey
59.
darlint! Phwat cana little bhoy do?" But she slept a happier woman
for her knight's vow.
As for Hughey, there was no sleep for him. By the first white light he
could see the two pathetic pinched profiles side by side, the
woman's and the babe's, both set in the same startling flat oval of
dark locks. The faces on the mattress yonder were so round and
ruddy! They had not begun to think, as Hughey had; even scant
dinners and no warmth in winter had not blighted one rose as yet in
those country cheeks. Up to yesterday, he had somehow found his
mother's plight bearable, thanks to the natural buoyancy of
childhood, and the hope, springing up every week, that next week
she would have a little less labor, a few more pence. Besides, it was
spring; and in spring hearts have an irrational way of dancing, as if a
fairy fiddler had struck up Garryowen. But now Hughey was sobered
and desperate.
There was no breakfast but a crust apiece. The McCarthy
grandmother, on the stairs, gave Nora, starting for school, some
fresh water-cresses. Just then Mrs. O'Kinsella happened to open the
door. Poor Nora had yielded to temptation and filled her mouth, and
pretended, holding her head down, to be much concerned about a
bruise on her knee. She could not look in her mother's honest eyes,
ignorant as these were of any blame in Nora. Mrs. O'Kinsella went
wearily to her charing, and seven-year-old Winny set up
housekeeping with Dan, the primroses and a teapot-shaped fish-
bone for their only toys. Hughey had already gone, nor was he at his
desk in the afternoon, when his teacher and Nora looked vainly for
him; nor did he return to his lodgings until after sundown. When he
came, he brought milk with him, earned by holding a gentleman's
horse at the Rotunda; and with that and some boiled potatoes, there
was a feast. Hughey's vocation, it would appear, had not yet
declared itself. He had haunted Stephen's Green and its sumptuous
purlieus in vain. He had not been asked to join partners with Messrs.
Pim, nor to accept a Fellowship at Trinity. The next day's, the next
month's history was no more heroic. There were so many of those
bright, delicate-featured, ragged-shirted boys in Dublin, coming
60.
about on foggymornings with propositions! The stout shop-keepers
were sated with the spectacle of the unable and willing.
The days dragged. An affable policeman who had known Hughey's
mother at home in New Ross, seeing him once gazing in a junk-shop
door, finally presented him to the proprietor: "Toby, allow me t'
inthroduce a good lad wants a dhrive at glory. Can ye tache um the
Black Art, now? He can turrun his hand to most anythin', and his
pomes, Oi hear, do be grand, for his age."
The junk-man, good-naturedly scanning Hughey, saw him burst into
tears, and beat the air, though the giant of the law had passed on.
That his chief and most secret sin should be mentioned aloud, to
prejudice the world of commerce against him, was horrible. His
mother had told on him! She must have found some lines on Winny's
slate last Sunday, entitled Drumalough: a Lament for the Fall of the
Three Kings, Written at Midnight. Worra, worra! Hughey was
descended, on the paternal side, through a succession of ever-falling
fortunes, from a good many more than three kings, and used to
wonder where their crowns and sceptres were, not that he might
pawn them, either. The O'Kinsellas were a powerful aboriginal sept
in the old days, and lived in fortress castles, and playfully carried off
cattle and ladies from their neighbors of the Pale. Malachi
O'Kinsella's mother, a heroine of romance who ran away with a
jockey lover, and never throve after, was of pure Norman blood, and
most beautiful, with gray eyes, water-clear, like Hughey's own, and
the same bronze-colored hair; and it was said she could play the
harp that soft it would draw the hearing out of your head with
ecstasy! Now the junk-man was fatherly, and presented Hughey, in
default of a situation, with a consolatory coin; but foregoing events
had been too trying for the boy's nerves: he dropped it, and fled,
sobbing. He simply couldn't live where his po'try was going to rise up
against him, and wail like a Banshee in the public ear. He charged, in
his wrath and grief, across the crowded bridge, and down the line of
quays east of it, straight into a fat, gray-headed, leather-aproned
person directing a group of sailors unloading a boat.
61.
This person, sentof Heaven, with miraculous suddenness, and with
musical distinctness, exclaimed: "'Aven't I been a-wishin' of 'im, and
directly 'e runs into me harms! Crawl into that barrel, sonny, and if
you 'old it steady, I'll 'eave you tuppence." Hughey, foreordained
likewise, crawled in. When he came out, Mr. J. Everard Hoggett
looked him over, from his moribund hat to his slight patrician ankle.
"I likes a boy wot's 'andy, and 'as little to sy, like you." He resumed
critically, "'E don't appear to be from any of 'Er Marjesty's carstles, 'e
don't. Perhaps 'e might like to 'ang about 'ere, and earn three bob a
week?" Hughey hugged his twopenny piece, blushed, trembled,
twisted his legs in the brown trousers too big for him, and replied in
gulps: "O sir! Yes, sir." Whereby his annals begin.
This perfectly amazing luck befell towards the end of May. Mr.
Hoggett, going home, beckoned him, took him into a little eating-
house, sat him down, paid for a huge order, and departed. "There's
a couple o' lion cubs hinside wot ought to be your westcot, needs
'am and heggs. Fill 'em full; and mind you come to-morrow at a
quarter to ight. I'll 'ave no lyzy lubbers alongside o' me." With which
fierce farewell, and disdaining thanks, Mr. Hoggett faded wholly
away.
Hughey, half-dazed, sat at a table alone, sniffing celestial fragrances
from the rear, with the joy in his breast jumping like a live creature
in a box. To quiet it, while he waited, he took up a torn journal
which was lying on the nearest chair. At first, what he read seemed
to have no meaning, but when some moments had passed, still
odorous only, and non-flavorous, Hughey's collected and intelligent
eye had taken in the dramatic political crisis, the stocks, the African
news, the prospects of Irish literature, and the latest London wife-
beating. On the advertisement page, one especial paragraph in
sensational print rooted his attention. This was it:—
"SERVANTS AND APPRENTICES, ATTENTION! Here is the best
Chance of your lives. It will Never come again. Trade with us,
and you lay the FOUNDATION of your FORTUNE! With every
sixpenny worth of goods bought of us on any Saturday night,
62.
we give aCOUPON on the Ninth anti-Sassenach Bank of Belfast.
Fifty of these entitle the Bearer at the end of the year to a gift
of TEN POUNDS IN GOLD!! Honesty the best Policy our motto.
Best Material at Lowest Prices; come and see. Do not Neglect
your own Good. McClutch & Gullim, Linen-drapers, No. 19— ——
St."
Hughey, the innocent prospective capitalist, took a stubby pencil
from the only sound pocket in his habiliments, and began to figure
on the margin of the paper; for he had an inspiration. "Mother would
be thundherin' rich!" was what flashed into his mind. Before he had
done with his emergency arithmetic, ham and eggs, with all their
shining train, were set before him. With them, he gallantly
swallowed his conscience, for Hughey, like a nobler Roman before
him, was resolving to be gloriously false, and, for piety's sake, to
trade his soul. He foresaw vaguely that he would not be allowed, out
of his royal wages of three shillings, to spend full half every Saturday
night, at McClutch and Gullim's; yet to do it was the imperative thing
now, and that he felt impelled to do it was his own super-private
business, and his warrant. Therefore would he keep his secret close,
and make what excuse he might. He could not even think of asking
advice; how should any one else be able to realize how he must act
towards his mother? The angels had given her into his hands; and
he knew at last what was to be done for her. She should be rich and
gay, and have a coach, perhaps, like a real lady; and Danny should
have a goat, and a sash with stripes in it, like the little twin
Finnegans; and the Misses Honora and Winifrid O'Kinsella should
walk abroad with parasols! Proper manœuvring now would fetch
twenty-five pounds sterling next summer. But he would hide away
what he bought, and never tell until the beatific hour when his
mother should have the money, and the linen, and the truth about
them, all together!
Hughey went home in a series of hops and whirls, like a kitten's. He
brought a flood of riotous sunshine in with him. It was supper-time;
the children had each a ha'penny bun, and some tea. Mrs. O'Kinsella
63.
was lying down,with an ache between her lungs and her spine,
after a long day's lifting and scrubbing. She felt the good news,
before the child spoke. "O mother! 'tis the most illigant thing's
happened: ye niver heard the loike." Hughey's pale comely little face
was radiant.
"Phwhere is ut, and phwhat d'ye get, dear?" Then Hughey screwed
up his courage, and told his only, his masterly lie: "North Wall,
mother; and a shillin' and six every week." "A shillin' and six!"
shrieked Nora. "O Hughey!" But the critic for whose opinion he cared
was not quite so enraptured. She smiled, and praised him, but took
it too tamely, her son thought. However, he reflected that she little
knew the felicities in store.
In the morning, his career began, and it maintained itself with vigor,
inasmuch as by the autumn he was of real value to his employers.
He had many duties and some trusts. His orders all came directly
from the benevolent bluff Mr. Hoggett, or from his mild reflection
and under-study, a small, bald, capable head-clerk from the north,
who was known as Jibtopsails; for what reason, Hughey could never
divine, unless it was that his ears were uncommonly large and
flapping. Jibtopsails sent him here and there with parcels and
messages, and he had been faithful; he had made no grave mistake
yet, nor had he been unpunctual. But every Saturday of his life saw
him posing as a purchaser at 19— —— Street, where a hard-
featured old woman, supposed mother of the supposed junior
partner, served him always with the same ironically deferent, "Good
day, sir; and what can I show you?" Jibtopsails inquired occasionally
after the health of Hughey's family, particularly after Hughey had
told him that Mrs. O'Kinsella was not so well as she used to be. For
the rest, the sympathy of that gentle cynic made the child's blood
run cold: he had such a paralyzing fear that Jibtopsails might call
there at the house, and talk to his mother, and say something about
three shillings a week! Kind people in the parish, if they knew, would
bring her in wood, and coal, and wine; but again, in the hallucination
of his jealous determined heart, the boy prayed passionately that
they might not know, and that he alone should be the deliverer. The
64.
dread of hissecret being found out, little by little made his life
intolerable. He had grown older since he had that to cherish in his
bosom, and it seemed less delicious than while as yet it was nothing
but a dream.
His mother broke down, and could toil no longer. Mrs. Drogan, who
lived downstairs, began to come up with her mending, and sit
between the bed and the window. Nora was clever, for so young a
girl; but she stumbled a great deal in her roomy charity boots, and
had to be scolded for awkwardness by Mrs. Drogan, who had
brought up sixteen rebels, and was disposed to command. As for
Winny and Dan, they made a noise, and therefore had to be exiled
to the street, foul and dangerous as it was, almost all day, while the
invalid slept the sleep of utter exhaustion. It occurred often to
Hughey, and with increasing force, that to secure a future good, he
was doing a very vicious wrong; that it would be far better for his
mother to have the money now, to provide comforts and make her
well, than for her to do without it now, and be too feeble in
consequence to enjoy it when it would come, all in a lump. Heavy
and sharp was this dilemma to the little fellow, as he labelled the
great bales, or set Mr. Hoggett's dusted ledgers back on their
shelves. "Phwhat ought I be doin'?" he would groan aloud, when he
was alone. If he confessed to his mother, and handed over hereafter
the total of his wages, there was an end to the big income sprouting
and budding wondrously at Belfast, the income which would be hers
yet, with ever so little patience. But if he should not confess, and,
meanwhile, if she should not recover,—what would all the world's
wealth be then to poor Hughey?
October was damp and dispiriting; Mrs. O'Kinsella coughed more,
but apparently suffered little. Hughey still brought her, week by
week, his pittance of a shilling and sixpence. Ill as she was, her alert
instinct divined that something ailed him; she pitied him, and
worried about him, and kissed his tears away with a blessing, very
often. Doctor Nugent was called in for the first time, one rainy noon.
He told Mrs. Drogan, laconically, that his patient was going to die,
and stopped her gesture of remonstrance. "Say nothing to those
65.
children of hers,"he added, aside, on the threshold; "there is no
immediate need of it, and the eldest looks melancholy enough
without it."
But the eldest was at his elbow. With a still ardor painful to see, he
raised himself close to the tall doctor, and whispered into his ear.
"Phwhat wud save me mother? Wudn't money do it, MONEY?" The
boy looked so thrillingly, impressively earnest that the doctor rose to
the occasion. "Perhaps! That is, a winter in France or Italy might
delay the end. But dear me! how on earth—" His voice wavered, and
he hurried down.
On the way back to the office, Hughey crossed Augier Street, and
stalked into McClutch and Gullim's. He had business with the old
woman, imminent business. Would the Ninth anti-Sassenach Bank of
Belfast advance half of an annual interest? that is, would they allow
him, Hugh O'Kinsella of Dublin, merchant's errand-boy, what was
due on his receipts of purchases up to date? He found that
circumstances over which he had no control prevented his waiting
until May: please might he draw out the eleven odd pounds now?
The old woman had recently had other queries of that nature, which
proved that the victims were getting restless; that it would soon be
advisable, in short, to strike camp, and betake herself and her
nefarious concerns to Leeds or Manchester. Her sourness vented
itself promptly on Hughey. Decidedly, the Ninth anti-Sassenach Bank
would do nothing of the sort; it was against the rules; it never
advanced cash except in case of death, when coupons from
McClutch and Gullim's would hold good for a life-insurance policy to
the corpse's relatives. "And now g'long to the divil wid ye, ye limb!"
concluded Mrs. Gullim, in a burst of vernacular indignation.
Hughey fairly reeled out to the pavement, with wheels humming in
his brain, and a large triangular rock, sharper than knives and
smeared with poison (a not unfamiliar rock, of late), lodged in the
middle of his throat. As he turned down the windy North Wall,
among the sleek cattle waiting for exportation, and pushed open the
66.
warehouse door bythe Liffey, Jibtopsails took his pen from behind
his capacious ear, and peered over his spectacles.
"Cead mille failthe, Brian Boruihme! and how is the royal fam——."
He got no further; the young face opposite was so awry with the
spirit's mortal anguish that Jibtopsails was truly sorry he had tried to
be jocose. It was almost a first offence.
And now, with much introspection, and heart-searching, and resolve,
Hughey's tragedy gathered itself together. On Sunday, after church,
he had occasion to go out of town. As he wished to deal with Nora,
he offered to give her a ride on the tram: a species of entertainment
which she accepted with enthusiasm. When they were at the end of
their route, they set forth on foot, up-hill, over two miles of exquisite
moorland, to the house of the retired first mate of the Grace
Greeley, who was summoned by the firm of Hoggett as witness in a
lawsuit. Nora was in her usual spirits, and her brother tried to wait
until they should show signs of flagging. O the heavenly freedom of
the country! the pleasant smell of damp leaves! But Hughey's heart
would not rise. As they passed the sheep-folds, the pretty huddled
creatures made Nora laugh, standing still, agape, in her blue faded
frock; and he grabbed her roughly by the arm, albeit his sad
forbearing tone was not rough. "D'ye love me at all, Nora?"
"That Oi do, Hughey O'Kinsella; and ye needn't be scrunchin' of me
to foind ut out."
"Nora!"
"Phwhat is ut?"
"There's somethin' Oi do be bound to say to ye." A pause.
"Can ye keep a secret?"
"Shure, Oi can."
"'Tis turrible."
"Niver ye moind, Oi'll keep ut!" said the loyal other.
67.
Hughey lifted hisface to the sweet blowy autumn afternoon, took
breath, and increased his pace. "Mother is loike to be doyin' soon.
Maybe ye didn't hear o' that. But she cud live a hunderd year if ut
wasn't so cruel poor we are. Oi've been a-thinkin' wan reason of ut
is she has too many childher. 'Tis good little Rosy is with the saints.
Childher all eats and wears clothes, and isn't much use. If mother
wasn't ill, there'd be nothin' the matther wid me; we cud go on
along, and Oi'd have power to do the beautiful things, Nora dear.
Ye'd all be proud as paycocks o' me whin next the cuckoo'll be in the
green bush down be the Barrow; only mother wud be undher the
ground. So 'tis long before that Oi must be doin' phwhat Oi'm
meanin' to do. Now's the toime for her to be cured, and the toime
for me to behave the usefullest to her is to-morrow, just afther Oi'm
dead."
The younger child was bewildered, over-awed. "May the Lorrud have
mercy upon your sowl, Hughey!" she murmured with vague
solemnity, taking in the legendary word "dead" and nothing else. Her
light feet ran unevenly beside his, up the slope and down the hollow,
and over stiles and pasture-walls, bright with their withering vines.
She was all ear when her brother began again, irrelevantly and more
softly, on his tremendous theme, so old now to his thoughts that he
was conscious of no solecism in the abrupt utterance of it. "Whin ye
dhrown, ye niver look bad at a wake. A man kilt in the battle looks
bad, but not a dhrowned man. 'Tis grand to be a marthyr to your
counthry; howsomiver, the guns isn't convanient, and Oi must hould
to the wather. The rest Oi can't tell, becaze ye're a woman, and
wudn't undhersthand; but there's pounds and pince in ut, and 'tis
the foine thing intoirely for mother." He turned upon her his most
searching gaze. "Ye'll be constant and koind to her, now? Ye'll be
runnin' and bringin' her a chair, and takin' the beef out o' your
mouth for her as long as ye live? (Shure Oi forgot there's goin' to be
tons o' beef for yez all.) Promus me, Nora." She looked at him, and
her wide blue eyes filled; and presently she sank down all in a heap,
her face in the grass, her heels in the air. It looked like revolt; but it
was regret, or rather the utter helplessness of either. The boy never
68.
flinched. "Promus me,Nora." "Oh, Oi do, brother Hughey, Oi do!"
she sobbed. He stood by her a moment, then with firmness followed
the path out of sight, his slender withdrawing figure significant
against the sky.
When he came back, the anxious Nora was on the road, whence she
could see far and wide. Little was said as they returned home,
through ways thickening with cabs and passers-by. But skirting Dean
Swift's dark Cathedral, they heard the treble voices at evensong in
the choir, and the grave sweetness of Tallis' old music seemed to
thaw Hughey's blood. He drew his sister closer as they walked, and
bent his curls over her. He had received a fresh illumination since he
spoke last.
"You're what mother needs," he whispered, "and so's Dan, seein'
he's no bigger than a fairy. But Oi'd be betther away, and so'd
Winny, for the sake o' leavin' plenthy to eat and plenthy o' room.
Ye'll give me Winny in her little coat whin Oi ax ye to-noight, will ye,
Nora?" The child glanced up mournfully at her ruling genius, without
a word, but with a look of supernatural submission. They went up
the rickety stairs, arm in arm.
Mrs. O'Kinsella, who had had a trying day, had just said to Mrs.
Drogan, rising with a view to supper for her husband: "Oi'm of that
moind meself. Johanna Carr'd be a widdy contint in her ould age, if
she'd had childher, if she'd had a son loike Hughey. Me blessid
darlint! he's gould an' dimonds. By the grace o' God Almighty, Oi cud
bow me head if He tuk the rest away from me, but He cudn't part
me and the bhoy, me and the bhoy." She began to cough again.
Her son asked to sit up late. "Oi'd be writin', mother," he pleaded.
Her pride in him came to her poor thin cheeks. "'Tis a Bard ye'll be
yet, loike the wans your father read about in the histhory!" Hughey
knew he had been misunderstood; but trifles were trifles, and must
be ignored, now that the hour of action had struck.
Having taken off his shoes, he sat down in the broken chair by the
table, with his pencil, and the paper which Jibtopsails had given him.