Introduction: Why You’re Reading This (And Why You Hate React)
Let me guess. You’re here because:
- Your company decided to “modernize” the perfectly functional jQuery application that’s been running since 2012
- Every job posting you see requires “3+ years of React experience” for a junior position
- You tried to create a simple counter button and ended up with 47 dependencies and a 2MB bundle
- Someone told you “React is just JavaScript” and you’re still trying to figure out what part of
useState(() => () => {})
looks like JavaScript to you
Welcome. You’re among friends here. Friends who remember when websites loaded instantly, when “View Source” actually showed you the content, and when you could understand your entire application without a Ph.D. in Computer Science and a subscription to seventeen Medium publications.
The Stockholm Syndrome Support Group
This book exists because React won. Not because it’s the best solution, not because it’s the most elegant, and certainly not because it’s the simplest. React won the same way VHS beat Betamax, the same way QWERTY became the standard keyboard layout despite being designed to slow typists down. React won through sheer force of corporate backing, community momentum, and the terrifying reality that it’s now easier to find a React developer than someone who knows how to properly use vanilla JavaScript.
And here you are, forced to learn it. Not because you want to, but because the market demands it. Because your team chose it. Because the tutorial you found uses it. Because resistance is futile.
What This Book Is (And Isn’t)
This is not another “React is amazing and here’s why” book. The internet is drowning in those, written by people who’ve apparently never had to explain to a client why their contact form now requires a build step.
This is also not a “React is terrible and you should never use it” rant, though it may occasionally feel like one. React has its place in the ecosystem, like how wasps have their place in nature - theoretically important, practically annoying, and you’d rather not deal with them directly.
This is a practical guide to learning React written for people who:
- Think components are what you plug into a motherboard
- Believe state should be a government concern, not a programming one
- Miss the days when refreshing a page actually refreshed the page
- Have ever typed
document.getElementById
and felt powerful - Still don’t understand why we need to compile HTML
The Five Stages of React Grief
Throughout this book, we’ll journey together through the five stages of React grief:
1. Denial: “This can’t be the best way to build web applications. There must be something I’m missing.”
2. Anger: “Why do I need three different files to display ‘Hello, World’? WHO THOUGHT THIS WAS A GOOD IDEA?”
3. Bargaining: “Maybe if I just use React for this one component… Maybe I can mix it with jQuery… Maybe CDN links will save me…”
4. Depression: “I spend more time configuring build tools than writing features. My node_modules folder is larger than my actual application. I’ve forgotten what HTML looks like.”
5. Acceptance: “Fine. This is my life now. At least the job market is good.”
What You’ll Actually Learn
Despite my tone (which will remain consistently sarcastic throughout this book, you’ve been warned), you will actually learn React. Properly. You’ll understand:
- Why React does things the way it does (even when it makes no sense)
- How to write React code that won’t make your colleagues cry
- When to use React patterns and when to run away screaming
- How to debug React applications without losing your sanity
- The actual problems React solves (there are some, I promise)
- How to work with React while maintaining some dignity
You’ll write real React code, build actual applications, and by the end, you’ll be able to hold your own in any React codebase. You might not like it, but you’ll be competent. Think of it as learning to perform surgery - you might feel queasy, but at least you’ll know where to cut.
A Warning About the Code Examples
The code examples in this book are real, functional React code. They will work. They will also occasionally make you question humanity’s life choices. When you see something like:
const [state, setState] = useState(() => {
const initialState = calculateInitialState();
return initialState;
});
useEffect(() => {
let cancelled = false;
(async () => {
if (!cancelled) {
setState(await fetchSomething());
}
})();
return () => {
cancelled = true;
};
}, []);
And you think “surely there’s a simpler way,” remember: there was. We had it. It was called fetch().then()
. But that’s not the React way.
The React Way™
Throughout this book, you’ll encounter “The React Way™” - a phrase that means “the convoluted but officially sanctioned method of doing something that used to be simple.” The React Way™ is not about simplicity, elegance, or developer happiness. It’s about consistency within the React paradigm, even when that paradigm makes you want to flip tables.
You’ll learn The React Way™ not because it’s good, but because fighting it is futile. Every attempt to do things simply in React will eventually be crushed by:
- Linting errors
- Code review comments
- Framework updates that break your clever workarounds
- Blog posts titled “You’re Doing It Wrong”
- That one teammate who read all the React documentation
Your Journey Starts Here
So pour yourself a strong coffee (you’ll need it for the webpack configurations), take a deep breath (you’ll need it for the error messages), and let’s begin this journey together.
Remember: you’re not learning React because you want to. You’re learning it because you have to. And that’s okay. We all have to do things we don’t want to do. Some people have to go to the dentist. Some people have to attend their cousin’s destination wedding. You have to learn React.
At least this book will make it entertaining.
By the end of this introduction, you should feel:
- Validated in your React skepticism
- Slightly amused despite your frustration
- Resigned to your fate
- Ready to learn React (grudgingly)
If you’re experiencing any enthusiasm or excitement about React, please consult a doctor immediately. That’s not normal, and this book may not be for you.
Now, let’s talk about why React exists in the first place, or as I like to call it, “The Problem That Wasn’t Really a Problem Until Facebook Made It One.”
Turn the page. Your transformation into a React developer begins now.
May God have mercy on your soul.