本指南的目的是把关于 React 核心概念的优质内容集中起来,以便快速参考。
请保持学习的心态。 阅读,尝试,乱搞(没关系)。
- 入门
- 历史
- 创建 React 项目
- 为什么使用 React?
- JSX
- 虚拟 DOM
- React 元素
- 组件
- 方法生命周期
- 组件类型
- 查找组件
- 属性
- 属性类型
- 状态
- Children API
- 绑定
- 事件
- 渲染
- Keys
- Refs
- Context
- 表单
- 控制组件
- React Ajax
- 模式
- Gotchas
- PATENTS
- Mixins
- 国际化
- 第三方库
- 性能
- 动画
- SVG & React
- React Style Guides
- Redux 和 Mobx
- 将 React 添加到现有 APP 中
- CSS 和 React
- 测试
- 讨论/会议视频
- 为 React JS 贡献代码
- 核心注释
- 通用的 React
- Deep Dive
- React Fiber
- 视频课程
- A11Y
- 讨论
- 练习
- 书籍
- Newsletters
- Interview Questions
- 工具
零基础,之前没有听说过 React?
- React 官方文档
- Thinking in React - Pete Hunt
- Pete Hunt: React: Rethinking best practices (JSConf EU 2013)
- 🔥 All the terrible things I did the first time I wrote a complex React App Raquel @raquelxmoss
- Teaching React Without Using React Eric Clemmons @ericclemmons
- 7 分钟学习 React this is a slightly dated but still really good starter
- React 介绍 Eric W. Greene / Microsoft Virtual Academy
- React 完整入门指南 - React, Webpack, Babel, Redux, React Router, SSR Brian Holt(@holtbt) for Frontend Masters worshop
- 书籍
- JSConfUS 2013 - Tom Occhino and Jordan Walke: JS Apps at Facebook The one where React became #OSS
- Our First 50,000 Stars Vjeux @vjeux
怎么创建一个新的 React 项目?
- 💯 create-react-app
- nwb if you need more control of the setup / config
Where can I find videos for using React Create App?
React Create App + Express @sprjrx @ladyleet
Can I play around with React Online?
- Composable components
- Easy to use with existing projects
- Declarative
- Functional / Immutable friendly
Is it fast?
- Is React.js fast? Faster than {framework}? … or are there more relevant questions to be asking? Jeff Barczewski @jeffbski
What so good about React?
- 7 Strengths of React Every Programmer Should Know About Samuel Hapák @samuha
- Design Principles
JSX 是什么?
JSX is a preprocessor step that adds XML syntax to JavaScript. You can definitely use React without JSX but JSX makes React a lot more elegant. - http://buildwithreact.com
- Tutorial: JSX
- JSX in Depth
- React’s JSX: The Other Side of the Coin Cory House @housecor
- What does JSX stand for? Tom Occhino @tomocchino
What does JSX really do for me?
This is the sort of stuff JSX saves you from having to manage Jonny Buchanan @jbscript
The Virtual DOM provides a lightweight implementation of the DOM and events system. Instead of dealing with the browser, you manipulate an in-memory version of the DOM.
What is the Virtual DOM?
- React's diff algorithm Christopher Chedeau @vjeux
- The one thing that no one properly explains about React — Why Virtual DOM Sai Kishore Komanduri @saiki
- Pete Hunt: The Secrets of React's Virtual DOM (FutureJS 2014)
Is the Virtual DOM all about speed?
No
See :
https://twitter.com/dan_abramov/status/790326092582252544 https://twitter.com/acdlite/status/779693791607336960
I wonder if we can reclaim the VDOM term to mean "Value DOM", as in Value Type, instead of "Virtual DOM"...? More accurate. @sebmarkbage
> It doesn't improve perf over hand written DOM code but it's hard to write on scale. React scales well. **@dan_abramov**
> React ultimately has to call browser APIs at some point, it can't possibly be faster than writing the same exact calls by hand **@dan_abramov**
>React will not do anything that you cannot. By definition everything it does can be reproduced (and some people have with other libraries/frameworks that follow similar conventions). The point is not that React does something that you can't, but rather that by introducing React to your application you are relieved of having to worry about manually handling your DOM, manually determining how to update it efficiently, minimizing traversals, etc. - [Sean Grogg](https://www.quora.com/Is-ReactJS-faster-than-direct-DOM-manipulation-with-JavaScript-or-jQuery)
Key Takeaway:
React keeps your product reasonably fast without you having to think about it all the time, or to jump through the hoops @dan_abramov
Elements are the smallest building blocks of React apps. Elements are what components are "made of ..." — React Docs
- What makes an 'Element' an 'Element' vs a component? Tim Arney @timarney
- Understanding the Difference Between React Elements and Components Alex Johnson
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. Conceptually, components are like JavaScript functions. - React Docs
What are some of your best practices when working with components?
- Keep it (F)ocused.
- Keep it (I)ndependent.
- Keep it (R)eusable.
- Keep it (S)mall.
- Keep it (T)estable.
- or in short,
FIRST
.
— Addy Osmani https://addyosmani.com/first
See : https://twitter.com/mxstbr/status/790084862954864640 Max Stoiber @mxstbr
Components have several "lifecycle methods" that allow you to override / run code at particular times.
What are Lifecycle Methods?
- React components lifecycle diagram Eduardo Bouças @eduardoboucas
- Going further with React lifecycle methods Jamie Barton
- Component Specs and Lifecycle
- My #reactjs component lifecycle cheatsheet for quick reference Peter Beshai @pbesh
- React component’s lifecycle Osmel Mora @osmel_mora
There are two main types of components Functional and Class Components
// Functional Component
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
// Class Component
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
Components can be used (composed) in many ways see the following links for patterns and thoughts on creating Components.
How do I decide what type of Component to use?
This comes down to a few factors... a primary one being you need to decide what a component should do.
See: Some Thoughts on Function Components in React from A. Sharif @sharifsbeat for some help deciding.
Also:
- React.Component vs React.createClass Naman Goel & Zach Silveira
- React.createClass versus extends React.Component Todd Motto
- 4 different kinds of React component styles Peter Bengtsson @peterbe
- Functions as Child Components and Higher Order Components Ken Ding
Stateless Function <Code />
- React Stateless Functional Components: Nine Wins You Might Have Overlooked Cory House @housecor
- Embracing Functions in React A. Sharif @sharifsbeat
Presentational and Container Components <Code />
- Presentational and Container Components Dan Abramov @dan_abramov
Higher-Order Components <Code />
- ReactCasts #1 - Higher Order Components Cassio Zen @cassiozen
- React Higher Order Components in depth @franleplant
- Higher Order Components: A React Application Design Pattern Jack Franklin @Jack_Franklin
- Mixins Are Dead. Long Live Composition Dan Abramov @dan_abramov
- Higher Order Components: Theory and Practice
- Real World Examples of Higher-Order Components Mehdi Mollaverdi @mehdimollaverdi
- Start Reacting: HOC OliverFencott @OliverFencott
Function as Child Components <Code />
- ReactCasts #2 - Function as Child Components Cassio Zen @cassiozen
- Function as Child Components Merrick Christensen @iammerrick
- I've mentioned this before, but I'm a big fan of child functions in React Brian Vaughn @brian_d_vaughn
What types of components are there?
- React Component Jargon as of August 2016 Anthony Comito @a_comito
Where are some good places to find components?
What are props?
props (short for properties) are a Component's configuration, its options if you may. They are received from above and immutable as far as the Component receiving them is concerned. - react-guide
See : props vs state
How do I pass props?
How do I pass boolean values?
- JSX
<Foo bar={true} />
and<Foo bar>
are equivalent Jack Franklin @Jack_Franklin
Should I use import, props, or context in React?
- Differences between require() and passing an object via prop or context Dan Abramov @dan_abramov
PropTypes are essentially a dictionary where you define what props your component needs and what type(s) they should be. - Niels Gerritsen
What are PropTypes?
- What are PropTypes? Ryan Glover @themeteorchef
Why are React PropTypes important?
- Why React PropTypes are important Niels Gerritsen @NielsG89
How do I validate props?
- Better Prop Validation in React Moe Sattler @travelperk
In one sense, “state” means the current visual representation of the app on screen... In the React sense, “state” is an object that represents the parts of the app that can change. Each component can maintain its own state, which lives in an object called this.state. - Dave Ceddia
What is state in React?
- A Visual Guide to State in React Dave Ceddia @dceddia
How do I handle state?
- The 5 Types Of React Application State James K Nelson @james_k_nelson
- State of React #1: A Stateless React App? James K Nelson @james_k_nelson
- A Case for setState Zack Argyle
- Where to Hold React Component Data: state, store, static, and this Sam Corcos
- How to handle state in React. The missing FAQ Osmel Mora @osmel_mora
- Should I keep something in React component state? I made a small cheatsheet. Dan Abramov @dan_abramov
- Best Practices for Component State in React.js Gabe Scholz @gabescholz
- Exploring React’s State Propagation Eric Greene @ericwgreene
How can I decouple state and UI?
- How to decouple state and UI Michel Weststrate @mweststrate
- ReactCasts #3 - React's Children API Cassio Zen @cassiozen
The JavaScript bind method has several uses. Typically, it is used to preserve execution context for a function that executes in another context.
What should you use for binding methods in React classes?
- To bind or not to bind? Dan Abramov @dan_abramov
- fat Arrow vS Autobind VS bind Dan Abramov @dan_abramov
What is this bind thing?
- Don't Use Bind When Passing Props Dave Ceddia
- 5 Approaches for Handling Binding Cory House @housecor
- How to Deal with
this
Reference Inside the Promise? Toptal Developers
How does the event system work in React?
- React events in depth Kent C. Dodds, Ben Alpert, & Dan Abramov
What should go in the render function?
- Return as soon as you know the answer @SimonRadionov
React uses keys to help with Reconciliation (i.e. how it calculates the DOM diff for each render).
<ul>
<li key="2015">Duke</li>
<li key="2016">Villanova</li>
</ul>
Why can't i put key in default props (or define the default somewhere else)?
What should I use for a key?
- Index as a key is an anti-pattern Robin Pokorný @robinpokorny
What are some examples where I should manually change a key?
- The key is using key Tim Arney @timarney
The ref attribute makes it possible to store a reference to a particular React element or component returned by the component render() configuration function. This can be valuable when you need a reference, from within a component, to some element or component contained within the render() function. - reactenlightenment.com
What are refs and are string refs are bad?
- Refs to Components
- Why do you use findDOMNode()? Dan Abramov @dan_abramov
- String refs are bad in quite a few ways Dan Abramov @dan_abramov
- ReactCasts #4 - Context (Part 1) Cassio Zen @cassiozen
- ReactCasts #5 - Context (Part 2) Cassio Zen @cassiozen
- How to handle React context in a reliable way Osmel Mora @osmel_mora
- How to safely use React context Michel Weststrate @mweststrate
- Context all the things with React Stephen Rivas Jr. (@sprjrx)
How can I build forms with React?
- Learn Raw React: Ridiculously Simple Forms James K Nelson @james_k_nelson
How can I validate form input?
- Elegant Form Validation Using React Jordan Schaenzle
- Building validated forms with great UX in React Marcela Hrdá
- react-validation
What is a controlled component?
Via Loren Stewart @lorenstewart111 React.js Forms: Controlled Components
A controlled component has two aspects:
-
Controlled components have functions to govern the data going into them on every onChange event, rather than grabbing the data only once, e.g. when a user clicks a submit button. This 'governed' data is then saved to state (in this case, the parent/container component's state).
-
Data displayed by a controlled component is received through props passed down from it's parent/container component.
This is a one-way loop – from (1) child component input (2) to parent component state and (3) back down to the child component via props – is what is meant by unidirectional data flow in React.js application architecture.
#React Ajax
What is the best practice for getting server data into React components?
It depends! See: React AJAX Best Practices Andrew H Farmer @ahfarmer
- Loading and Using External Data in React Chris Coyier @chriscoyier
- React Patterns @chantastic
- React.js in patterns Krasimir Tsonev
- Patterns For Style Composition In React Brent Jackson @jxnblk
- Make Your React Components Pretty Mark Brouch @markbrouch
What are some React Gotchas?
- React Gotchas Dave Ceddia
What's all this stuff I hear about Facebook PATENTS clause?
- Some links to point people to when they misinterpret PATENTS clause or spread false claims Dan Abramov @dan_abramov
- React’s license: necessary and open? Luis Villa @luis_in_140
Why are Mixins Considered Harmful?
- Mixins Considered Harmful Dan Abramov @dan_abramov
How should I handle internationalization?
- Internationalization in React Preethi Kasireddy
What repos should I checkout for internationalization?
- react-intl
- react-localize @sprjrx
How do I use third party libraries?
- Integration with Third Party Libraries Rally Coding
How can I make my app faster?
- Component Rendering Performance in React Grgur Grisogono
- Don‘t use PureComponent everywhere. Measure Dan Abramov @dan_abramov
- React.js pure render performance anti-pattern
- Should I use shouldComponentUpdate? James K Nelson @james_k_nelson
- Reconciliation
- Quick slides on #reactjs performance Juho Vepsäläinen @bebraw
How do I animate things in React?
- 🔥 💯 [Animating In React](https://youtu.be/Fk--XUEorvc?t=2344 Sarah Drasner) @sarah_edo
- UI Animations with React — The Right Way Joe Davis
- Animations with ReactTransitionGroup Chang Wang @CheapSteak
Is there declarative api for animations?
How can I animate Page Transitions?
- React Page Transition Animations Huan Ji
What are some good repos to checkout for animation in React?
How do I work with SVG's in React?
Where can I find some good React style guides?
What's (Redux/Mobx)?
Do I need to use (Redux/Mobx)?
-
You don’t need Redux if your data never changes. The whole point of it is managing changes. Dan Abramov @dan_abramov
-
You Might Not Need Redux Dan Abramov @dan_abramov
-
Redux or MobX: An attempt to dissolve the Confusion Robin Wieruch @rwieruch A How to scale React-Redux apps?
-
About folder structure, styling, data fetching, etc. Max Stoiber @mxstbr
How do I start adding React to an existing app?
- How to Sprinkle ReactJS into an Existing Web Application Andrew Del Prete @andrewdelprete
- Don't Rewrite, React! Ryan Florence
- Migrating Safely to React Jamis Charles
What about styling things in React?
You can use plain CSS or any preprocessor (Sass, Less etc...) with React. React outputs standard markup so technically you can keep doing what you've been doing.
Using CSS to style our React content is actually as straightforward as you can imagine it to be. Because React ends up spitting out regular HTML tags, all of the various CSS tricks you've learned over the years to style HTML still apply. - kirupa
- What to use for React styling? Andrew H Farmer
- Styling React survivejs.com
- Styling in React kirupa
- Styling React Components in JavaScript Michael Chan
What about using Bootstrap with React?
- React-Bootstrap - Bootstrap 3 components built with React
- bootstrap-loader -Load Bootstrap styles and scripts in your Webpack bundle
There are various approaches for React that allow us to push styling to the component level. - survivejs.com
What repos should I checkout for styling at the component level?
- styled-components + Styling React Applications @mxstbr
- glamor @threepointone
- aphrodite- Khan Academy
Note: Also see - Styled components or Glamor?
What's the difference between what’s called "inline styles" and what's called “CSS-in-JS”?
- Writing your styles in JS ≠ writing inline styles Max Stoiber @mxstbr
I just need some simple inline styles ... What's the most basic way to use inline styles with React?
- React Docs Inline styles
- classnames - A simple javascript utility for conditionally joining classNames together. @JedWatson
What resources are available discussing the pros and cons of inline styles and CSS in JS?
- PANEL ON 'INLINE STYLES' @ShopTalkShow
- CSS in JS may not be the solution to all your problems Alan Souza
- CSS in JS + CSS Modules@dadsindev
- CSS in JS tech chat Kent C. Dodds & Sarah Drasner
What about using CSS Modules for styling?
- css-modules @markdalgleish
- CSS Modules by Example Andrew H Farmer
There's too many CSS in JS options how can I compare them?
- React: CSS in JS techniques comparison Michele Bertoli @MicheleBertoli
- [Comparison of CSS in JS Libraries for React](https://github.com/FormidableLabs/radium/tree/master/docs/comparison - radium)
How can I style/build a component that's very reusable customizable?
- Testing React Applications Jack Franklin
- People seem to laugh at this but I think it’s actually pretty reasonable Dan Abramov @dan_abramov
- Worthwhile Testing: What to test in a React app (and why) Dave Ceddia @dceddia
- Getting Started with TDD in React Dave Ceddia @dceddia
Where can I learn about Contributing to React JS?
- Contributing to React JS Kent C. Dodds
Where can I find out what's going on with React / Upcoming versions?
- React on the Server for Beginners Luciano Mammino @loige
- Implementation Notes - How React Really Works Dan Abramov @dan_abramov
- Building React From Scratch Paul O'Shannessy @zpao
- React Architecture – OSCON Christopher Chedeau @vjeux
- ReactJS: Under The Hood Boris Dinkevich @BorisDinkevich
- REACT INTERNALS Zack Argyle @ZackArgyle
What is React Fiber?
- Experimental - React Fiber Architecture Andrew Clark @acdlite
- Experimental - What's Next for React Andrew Clark @acdlite
Is Fiber ready yet?
How can I contribute to Fiber?
What are some good video resources/courses to learn React?
- https://egghead.io/courses/react-fundamentals FREE (+ paid for others)
- https://reactforbeginners.com
- https://app.pluralsight.com/courses/react-redux-react-router-es6
- https://www.pluralsight.com/courses/react-flux-building-applications
- https://frontendmasters.com/courses/react-intro (they have a bunch)
- http://courses.reactjsprogram.com/courses/reactjsprogrambundle
- https://LearnRedux.com
- https://egghead.io/courses/manage-complex-state-in-react-apps-with-mobx
- https://www.udemy.com/react-redux/
#A11Y
What about accessibility?
- How to design for accessibility Note: not specific to React but a solid primer on the topic
How do I handle A11y in React
- Excerpt from React.js Conf 2015 - Hype! Ryan Florence
- Bringing the Web Back to the Blind by Ryan Florence Note: not specific to React
- React to the Future - Slide Deck Elijah Manor @elijahmanor
- React Things - PDF Slides Jeff Winkler @winkler1
Where can I get React training?
Micheal Jackson @mjackson & Ryan Florence @ryanflorence
*Brian Holt* @holtbt
- https://btholt.github.io/es6-react-pres
- https://btholt.github.io/complete-intro-to-react
- https://github.com/btholt/react-redux-workshop
Where can I find some good books about React?
- React Enlightenment Cody Lindley @codylindley
- Build your first real world React.js application Max Stoiber @mxstbr
- SurviveJS React
- Fullstack React
Where can I find React specific newsletters?
- 12 Essential React.js Interview Questions
- React Interview Questions
- quiz.md Dan Abramov @dan_abramov
- 5 Essential React.js Interview Questions
- The Vital Guide to React.js Interviewing
- StoryBook (A visual way to develop your UI components. Show them in different states and develop them interactively).
See
Example StoryBook + React Storybooks meets Create React App - React Developer Tools
- why-did-you-update - Puts your console on blast when React is making unnecessary updates.
- Performance Tools