惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
T
Tor Project blog
博客园_首页
F
Fortinet All Blogs
V
V2EX
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
Y
Y Combinator Blog
博客园 - 【当耐特】
Jina AI
Jina AI
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
Spread Privacy
Spread Privacy
C
Cyber Attacks, Cyber Crime and Cyber Security
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Apple Machine Learning Research
Apple Machine Learning Research
V2EX - 技术
V2EX - 技术
Latest news
Latest news
L
LINUX DO - 最新话题
IT之家
IT之家
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 叶小钗
博客园 - Franky
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
量子位
博客园 - 聂微东
MyScale Blog
MyScale Blog
S
Security @ Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
小众软件
小众软件
S
Secure Thoughts
D
Darknet – Hacking Tools, Hacker News & Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News | PayPal Newsroom
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
有赞技术团队
有赞技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Vulnerabilities – Threatpost
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
T
Troy Hunt's Blog
美团技术团队

Kent C. Dodds Blog

Implementing Hybrid Semantic + Lexical Search Simplifying Containers with Cloudflare Sandboxes Migrating to Workspaces and Nx Offloading FFmpeg with Cloudflare Building Semantic Search on my Content Helping YOU ask ME questions with AI How I used Cursor to Migrate Frameworks The Dow's Start on the Covenant Path 2025 in Review The next chapter: EpicAI.pro AI is taking your job How I increased my visibility Launching Epic Web 2023 in Review Stop Being a Junior RSC with Dan Abramov and Joe Savona Live Stream Fixing a Memory Leak in a Production Node.js App 2022 in Review My Car Accident I Migrated from a Postgres Cluster to Distributed SQLite with LiteFS I'm building EpicWeb.dev A review of my time at Remix Remix: The Yang to React's Yin How I help you build better websites Why I Love Remix The State Initializer Pattern Get a catch block error message with TypeScript Building an awesome image loading experience How Remix makes CSS clashes predictable Introducing the new kentcdodds.com How I built a modern website in 2021 How to use React Context effectively Static vs Unit vs Integration vs E2E Testing for Frontend Apps The Testing Trophy and Testing Classifications Array reduce vs chaining vs for loop Don't Solve Problems, Eliminate Them Super Simple Start to Remix Super Simple Start to ESModules in Node.js JavaScript Pass By Value Function Parameters How to write a Constrained Identity Function (CIF) in TypeScript How to optimize your context value How to write a React Component in TypeScript TypeScript Function Syntaxes Listify a JavaScript Array Build vs Buy: Component Libraries edition Using fetch with TypeScript Wrapping React.useState with TypeScript Define function overload types with TypeScript 2020 in Review Business and Engineering alignment Hi, thanks for reaching out to me 👋 useEffect vs useLayoutEffect Super simple start to Firebase functions Super simple start to Netlify functions Super Simple Start to css variables Favor Progress Over Pride in Open Source Testing Implementation Details How getting into Open Source has been awesome for me useState lazy initialization and function updates Use ternaries rather than && in JSX Application State Management with React Use react-error-boundary to handle errors in React JavaScript to Know for React How I structure Express apps What open source project should I contribute to? When I follow TDD AHA Programming 💡 How I Record Educational Videos Should I write a test or fix a bug? Stop mocking fetch Intentional Career Building Improve test error messages of your abstractions Tracing user interactions with React Eliminate an entire category of bugs with a few simple tools Common mistakes with React Testing Library Super Simple Start to React Stop using client-side route redirects The State Reducer Pattern with React Hooks Function forms Replace axios with a simple custom fetch wrapper How to test custom React hooks React Production Performance Monitoring Should I useState or useReducer? Stop using isLoading booleans Make Your Test Fail Make your own DevTools An Argument for Automation Fix the "not wrapped in act(...)" warning Super Simple Start to ESModules in the Browser Implementing a simple state machine library in JavaScript 2010s Decade in Review Why users care about how you write code Why I avoid nesting closures Don't call a React function component Why your team needs TestingJavaScript.com Inversion of Control Understanding React's key prop How to Enable React Concurrent Mode How to add testing to an existing project Profile a React App for Performance
How to React ⚛️
2021-11-03 · via Kent C. Dodds Blog

The best way to learn React is... Honestly, it's different for everyone. But here's some handy advice from someone who's taught React to tens (hundreds?) of thousands of developers.

Abstraction

Let's start out talking about abstraction. Here's an example of an abstraction from youmightnotneedjquery.com:

// $(el).toggleClass(className);

function toggleClass(el, className) {
	if (el.classList) {
		el.classList.toggle(className)
	} else {
		var classes = el.className.split(' ')
		var existingIndex = -1
		for (var i = classes.length; i--; ) {
			if (classes[i] === className) existingIndex = i
		}

		if (existingIndex >= 0) {
			classes.splice(existingIndex, 1)
		} else {
			classes.push(className)
		}

		el.className = classes.join(' ')
	}
}

Pretty handy. But here's the kicker... If you don't need to support IE8, then you can actually change that to:

// $(el).toggleClass(className)

function toggleClass(el, className) {
	el.classList.toggle(className)
}

Which, quite honestly is an abstraction that shouldn't exist at all... el.classList.toggle(className) is simple enough all on its own.

So here's what you need to know about an abstraction before you adopt it into your application or workflow:

  1. What is the benefit of this abstraction?
  2. What is the cost of this abstraction?

If you don't know those things, then you run the risk of paying a cost for a solution for a problem you don't have. A cost with no benefit is not a good deal!

An important part of understanding the benefits and costs is feeling the pain of the problem that the abstraction solves. This is why it's important for you to learn React and its ecosystem in the right order to make certain that you're not overwhelmed by too much to learn at once and using abstractions effectively.

For more on this, check out AHA Programming 💡.

Side note... Want to just play around with stuff? Want to just ship stuff? That's totally cool. Just recognize you don't know the trade-offs and that could bite you in the future. If the future doesn't matter that much then don't worry about it!

Start with JavaScript + Modern JS

One of the things I love about React is how much JavaScript it is. If you can build a simple app with regular JavaScript and DOM APIs then you'll understand the benefits of React much better. You'll also be much more effective using React because honestly, 90% of being effective with React is understanding JavaScript well. For this, I suggest reading my blog post "JavaScript to Know for React". Also check out JavaScript30.com (totally free) and BeginnerJavaScript.com (not free) both by Wes Bos.

In addition, knowing modern JavaScript features will go a long way. Because JSX (more on this later) requires a compiler, most React developers take modern JavaScript features/compilers for granted. So most tutorials and examples will assume you have a basic understanding of modern JavaScript features. For this, I suggest my ES6 and Beyond Workshop (totally free) which is a recording of a workshop I gave at PayPal.

Next, let's learn React

Too many "beginner React" material starts with JSX and a bunch of tools. React itself is remarkably simple (and the docs are pretty good, the beta docs are even better). The simplicity of React is what I love about it. Sadly, everything around it can get complicated quickly and it can be hard to know where the lines are between React and the tools and libraries you use it with. Because of this, I've created The Beginner's Guide to React absolutely free on egghead.io. It starts with everything in index.html files which I think is important. You don't need any tooling at all to use React. I've built real side-projects with this approach for lightning fast iteration and deployment. I seriously can't think of a faster way to build those kinds of simple apps, and it allows you to side-step a ton of complexity and get to building and shipping apps fast. Learn more about this approach in my post Super Simple Start to React.

The last lesson of my free egghead course shows you how to use CodeSandbox.io to create your app entirely in the browser and download that to your computer to a create-react-app application.

You don't need anything installed to get a really long way! And once you do, you can get really far without having to configure any tools. I know of several companies shipping their application with create-react-app.

Also, I have a ton of React-related content on my blog 😅

If you're looking for the fast-pass to learning React, then look no farther than EpicReact.Dev. It will teach you everything that my Beginner's Guide to React does and then WAY more. EpicReact can be your companion from the start of your journey with React all the way through becoming a complete boss at this stuff. And it does this so effectively thanks to the exercise-driven approach. You'll spend WAY more time with your fingers at the keyboard applying what you're learning than any typical online course will give you. Don't miss EpicReact.Dev.

Dependencies and npm

Once you've decided that you don't want to write your own version of every component under the sun, you can start looking into dependencies. There are a TON of components out there and here is where you really need to start asking the questions of "what's the cost" and "what's the benefit." Try really hard to not add a dependency until after you've felt the pain it's supposed to solve. It will make you more effective at using the dependency.

I suggest reading through the npm documentation in an afternoon. Seriously, do it. There's some really valuable information in there.

In addition, when you start using dependencies, you're going to want to learn how to import those dependencies. I have a talk called "More than you want to know about ES6 Modules" which you'll probably find packed with useful information about the ES Modules syntax.

Remix

Now it's time to get serious about building a real-world application. No matter what you plan to build with React on the web, you'll be well served to use Remix as your framework of choice. It has allowed me to build this website with excellent performance while maintaining a fantastic codebase I love working in.

To learn Remix, I recommend the official documentation. I also have some Remix content on my blog that could be helpful to you.

State management

Most of typical state management will be managed for you by Remix, but for UI state (state that's not persisted in a backend), you're going to need to understand how to manage state within React.

When you learned React, you learned about the useState API. You probably also learned about Lifting State Up. This can actually get you a long way with React and I encourage you to keep doing this as long as you're able. Eventually you may start running into some trouble with "the prop-drilling problem." You'll know it when you feel it. When this happens, then I suggest you give my blog post "Application State Management" a read through.

TL;DR: React is an Application State Management library and you don't need Redux

Component Styling

I honestly cannot recommend tailwind enough. Once your app has more than a few hundred lines of CSS, you'll find that tailwind can really simplify things conceptually for you. It's "a utility-first CSS framework for rapidly building custom designs."

That said, Remix has a terrific mechanism for loading (and unloading!!) CSS on a per-route basis, so you may be able to manage just writing regular CSS for quite some time before needing to reach for something like Tailwind.

And on...

From here I suggest you dive in deeper into React. I have my Advanced React Component Patterns course on egghead.io which can give you a lot of really good information (but you can get a more up-to-date version of this content on EpicReact.dev anyway, so I suggest you just grab that).

Conclusion

I hope that this gives you (and your friends) a path for how to learn react as well as where to start when building React applications. Adding abstractions to your application too early makes them less flexible, so I would generally follow this pattern when building apps as well. Good luck!