├── docs ├── 01-element-factory.html ├── 07-property-example.html ├── 15-simple-integration.html ├── 08-nested-components.html ├── 05-properties.html ├── 06-property-types.html ├── 03-nested-elements.html ├── 14-references.html ├── 02-jsx.html ├── 00-object-elements.html ├── 04-components.html ├── 13-element-refactor.html ├── 09-component-classes.html ├── 11-lifecycle-methods.html ├── 10-example-app.html ├── 12-component-refactor.html └── 16-advanced-integration.html ├── README.md ├── summary.zh.md ├── LICENSE └── summary.md /docs/01-element-factory.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 01 Element Factory - React From Zero 4 | 5 | 6 | 7 | 8 |
9 | 10 | -------------------------------------------------------------------------------- /docs/07-property-example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 07 Property Example - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 37 | -------------------------------------------------------------------------------- /docs/15-simple-integration.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 15 Simple Integration - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 14 | 15 |
16 | 17 | 39 | -------------------------------------------------------------------------------- /docs/08-nested-components.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 08 Nested Components - React From Zero 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | -------------------------------------------------------------------------------- /docs/05-properties.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 05 Properties - React From Zero 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | -------------------------------------------------------------------------------- /docs/06-property-types.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 06 Property Types - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 12 | 13 |
14 | 15 | 51 | -------------------------------------------------------------------------------- /docs/03-nested-elements.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 03 Nested Elements - React From Zero 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 58 | -------------------------------------------------------------------------------- /docs/14-references.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 References - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | -------------------------------------------------------------------------------- /docs/02-jsx.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 02 JSX - React From Zero 4 | 5 | 6 | 7 | 8 | 14 | 15 |
16 | 17 | -------------------------------------------------------------------------------- /docs/00-object-elements.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 00 Object Elements/React元素长什么样 - React From Zero 4 | 5 | 6 | 7 | 8 |
9 | 10 |
11 | 12 | -------------------------------------------------------------------------------- /docs/04-components.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 04 Components - React From Zero 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 79 | -------------------------------------------------------------------------------- /docs/13-element-refactor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 Element Refactor - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 103 | -------------------------------------------------------------------------------- /docs/09-component-classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 09 Component Classes - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 |
15 | 16 | 101 | -------------------------------------------------------------------------------- /docs/11-lifecycle-methods.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 Lifecycle Methods - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 115 | -------------------------------------------------------------------------------- /docs/10-example-app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 Example App - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 129 | -------------------------------------------------------------------------------- /docs/12-component-refactor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 Component Refactor - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /docs/16-advanced-integration.html: -------------------------------------------------------------------------------- 1 | 2 | // 3 | 4 | 16 Advanced Integration - React From Zero 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 |
18 | 19 | 132 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React From Zero [![explain]][source] [![translate-svg]][translate-list] 2 | 3 | [explain]: http://llever.com/explain.svg 4 | [source]: https://github.com/chinanf-boy/Source-Explain 5 | [translate-svg]: http://llever.com/translate.svg 6 | [translate-list]: https://github.com/chinanf-boy/chinese-translate-list 7 | 8 | React 简单 (至少99% ES2015 ) 例子 9 | 10 | 一切都在浏览器中运行,无需手动预编译。 11 | 12 | ## 校对 ✅ 13 | 14 | 15 | 16 | 17 | 18 | 翻译的原文 | 与日期 | 最新更新 | 更多 19 | ---|---|---|--- 20 | [commit] | ⏰ 2018 6.30 | ![last] | [中文翻译][translate-list] 21 | 22 | [last]: https://img.shields.io/github/last-commit/kay-is/react-from-zero.svg 23 | [commit]: https://github.com/kay-is/react-from-zero/tree/b31878c2c1ba423fede7542c473092bba5943dfa 24 | 25 | 26 | 27 | ### 贡献 28 | 29 | 欢迎 👏 勘误/校对/更新贡献 😊 [具体贡献请看](https://github.com/chinanf-boy/chinese-translate-list#贡献) 30 | 31 | 32 | ## 生活 33 | 34 | [If help, **buy** me coffee —— 营养跟不上了,给我来瓶营养快线吧! 💰](https://github.com/chinanf-boy/live-need-money) 35 | 36 | ## 课堂 37 | 38 | [Lesson 0 - Object Elements](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/00-object-elements.html) React元素长什么样 - 39 | [预览](https://chinanf-boy.github.io/react-from-zero/00-object-elements.html) 40 | 41 | --- 42 | 43 | [Lesson 1 - Element Factory](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/01-element-factory.html) React元素-生产函数 `React.createElement` - 44 | [预览](https://chinanf-boy.github.io/react-from-zero/01-element-factory.html) 45 | 46 | --- 47 | 48 | [Lesson 2 - JSX](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/02-jsx.html) - JSX 写在`js`中的`XHTMl`样式 49 | [预览](https://chinanf-boy.github.io/react-from-zero/02-jsx.html) 50 | 51 | --- 52 | 53 | [Lesson 3 - Nested Elements](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/03-nested-elements.html) - 嵌套`React`元素 54 | [预览](https://chinanf-boy.github.io/react-from-zero/03-nested-elements.html) 55 | 56 | --- 57 | 58 | [Lesson 4 - Components](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/04-components.html) - 组件怎么来的 59 | [预览](https://chinanf-boy.github.io/react-from-zero/04-components.html) 60 | 61 | --- 62 | 63 | [Lesson 5 - Properties](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/05-properties.html) - 属性,来了 64 | [预览](https://chinanf-boy.github.io/react-from-zero/05-properties.html) 65 | 66 | --- 67 | 68 | [Lesson 6 - Property Types](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/06-property-types.html) - 属性类型验证 69 | [预览](https://chinanf-boy.github.io/react-from-zero/06-property-types.html) 70 | 71 | --- 72 | 73 | [Lesson 7 - Property Example](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/07-property-example.html) - 属性的示例 74 | [预览](https://chinanf-boy.github.io/react-from-zero/07-property-example.html) 75 | 76 | --- 77 | 78 | [Lesson 8 - Nested Components](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/08-nested-components.html) - 嵌套组件 79 | [预览](https://chinanf-boy.github.io/react-from-zero/08-nested-components.html) 80 | 81 | --- 82 | 83 | [Lesson 9 - Component Classes](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/09-component-classes.html) - 组件类 84 | [预览](https://chinanf-boy.github.io/react-from-zero/09-component-classes.html) 85 | 86 | --- 87 | 88 | [Lesson 10 - Example App](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/10-example-app.html) - 任务列表应用的示例 89 | [预览](https://chinanf-boy.github.io/react-from-zero/10-example-app.html) 90 | 91 | --- 92 | 93 | [Lesson 11 - Lifecycle Methods](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/11-lifecycle-methods.html) - 生命周期钩子函数 94 | [预览](https://chinanf-boy.github.io/react-from-zero/11-lifecycle-methods.html) 95 | 96 | --- 97 | 98 | [Lesson 12 - Component refactor](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/12-component-refactor.html) - 组件的重构 99 | [预览](https://chinanf-boy.github.io/react-from-zero/12-component-refactor.html) 100 | 101 | --- 102 | 103 | [Lesson 13 - Element Refactor](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/13-element-refactor.html) - `React`元素重构 104 | [预览](https://chinanf-boy.github.io/react-from-zero/13-element-refactor.html) 105 | 106 | --- 107 | 108 | [Lesson 14 - References](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/14-references.html) - `元素/组件`引用 109 | [预览](https://chinanf-boy.github.io/react-from-zero/14-references.html) 110 | 111 | --- 112 | 113 | [Lesson 15 - Simple Integration](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/15-simple-integration.html) - 同步简单库的整合 114 | [预览](https://chinanf-boy.github.io/react-from-zero/15-simple-integration.html) 115 | 116 | --- 117 | 118 | [Lesson 16 - Advanced Integration](https://github.com/chinanf-boy/react-from-zero/blob/master/docs/16-advanced-integration.html) - 高级库的整合 119 | [预览](https://chinanf-boy.github.io/react-from-zero/16-advanced-integration.html) 120 | 121 | --- 122 | 123 | 124 | ## More 125 | 126 | [更多中文翻译](https://github.com/chinanf-boy/chinese-translate-list) -------------------------------------------------------------------------------- /summary.zh.md: -------------------------------------------------------------------------------- 1 | 2 | ## menu 3 | 4 | ### Lesson 0 - Object Elements 5 | 6 | `React`使用`ES2015`符号`"tag"`它的元素对象. 7 | 8 | 它在旧版浏览器上使用幻数作为回退. 9 | 10 | `React`使用虚拟`DOM`元素,这成为真实的`DOM`在渲染上的元素. 11 | 12 | 虚拟`DOM`元素可以被定义为一个简单的对象文字. 13 | 14 | 通常你会使用`React`. `createElement()`创建一个元素. 15 | 16 | 这就是a的返回值`React`. `createElement()`电话可能看起来像. 17 | 18 | 这个特殊的财产将被检查`React`确保这个对象是一个`React`元素而不仅仅是一些用户数据`React.createElement()`为你设置 19 | 20 | 这也将被检查`React`. 21 | 22 | 我们稍后将讨论引用,但如果您不使用它们,则必须将其设置为null,而不是未定义的 23 | 24 | 这定义了HTML标签 25 | 26 | 这定义了传递给元素的属性 27 | 28 | 在这个例子中,只有一个文本节点作为子节点a`CSS`类 29 | 30 | 样式可以作为对象文字传递`React`使用camelCase而不是虚线 (例如`CSS/D3`做) 31 | 32 | 事件处理程序也可以作为属性添加`React`使用综合事件,基本上试图规范化浏览器的行为 33 | 34 | 另一个没有太多配置的元素`React`需要一个`DOM`元素作为渲染目标 35 | 36 | `ReactDOM`OM负责将元素插入到DOM中 37 | 38 | ### Lesson 1 - Element Factory 39 | 40 | `React.createElement()`需要类型,属性,孩子. 这比使用普通对象文字的冗长,它隐藏了第0课中提到的$$ type / Symbol和ref 41 | 42 | 第二个参数是属性对象,如果为空,则必须为null 43 | 44 | ### Lesson 2 - `JSX` 45 | 46 | 现在我们将使用`JSX`,这需要转换为`JavaScript`. 为此我们将使用`Babel`. `Babel`通常用于转换`ES2015`至`ES5`,但它也可以转换`JSX`至`ES5`. `Babel`浏览器版本使用文本/ babel脚本标签. 47 | 48 | `JSX`是创造元素的惯用方式. 基本上是这样`XHTML`同`{}`对于动态内容,也必须将class称为className 49 | 50 | 是相同的 51 | 52 | `JSX`特别是构成大多数的简单元素尤其闪耀 53 | 54 | 是相同的 55 | 56 | 正如我们所看到的,其他一切和以前一样 57 | 58 | ### Lesson 3 - Nested Elements 59 | 60 | 元素可以嵌套,这将导致嵌套`React.createElement()`reateElement调用正如你可以想象的那样,不需要写这个`JSX`会很乏味 61 | 62 | 他们也可以像第2课中提到的那样包含`JavaScript`在`{}` 63 | 64 | `JavaScript`插入在属性中的语法与在普通文本或元素中的语法相同 65 | 66 | 这个`JavaScript`也可以包含元素,也可以将对象"散布"为属性 67 | 68 | ### Lesson 4 - Components 69 | 70 | 主要卖点之一`React`是它的组件系统组件被用来封装元素和它们的行为,将它们视为MVC的控制器和视图的混合 71 | 72 | 这里我们使用独立元素和一些数据 73 | 74 | 这里的元素被封装在一个简单的组件函数中它们必须以大写字母开头,并返回恰好一个根元素 (带或不带嵌套元素) (之前`React`16) 75 | 76 | 以来`React`16.0.0,组件也可以返回元素数组. 为此,不创建额外的包装器元素. 有一点需要注意的是,与我们在渲染数组时所做的相似,我们必须为数组中的每个元素添加一个唯一键 (在下一课中我们会看到更多内容) 77 | 78 | 以来`React`16.2.0,我们可以使用称为片段的特殊"包装器"组件,它们的行为相同 (不创建额外的包装器元素) ,但是不需要设置明确的键 (片段可以在引擎盖下进行) 79 | 80 | 一个组件函数可以像一个元素一样使用 81 | 82 | 这转化为a`React.createElement()`调用null表示没有设置属性 83 | 84 | 供参考`React`-内部`
`标签 85 | 86 | 被转换为 87 | 88 | ### Lesson 5 - Properties 89 | 90 | 组件与元素一样也可以使用属性 91 | 92 | 这也适用于对象和传播 (...) 运算符 93 | 94 | 这允许具有动态内容的组件 95 | 96 | 如果一个数组被用作"子节点",那么每个孩子都需要一个唯一的键属性 97 | 98 | ### Lesson 6 - Property Types 99 | 100 | PropType已从中删除`React`16,现在是他们自己的套餐 101 | 102 | 组件被创建来封装应该在一起的东西并重用. 重复使用要求组件的用户提供正确的属性,以便我们可以定义每个属性的类型并设置默认值 103 | 104 | 将propTypes (function-) 属性添加到组件函数以使其验证其 ( (element) ) 属性 105 | 106 | `React`为我们提供了一堆类型,比如字符串 107 | 108 | 如果用户未提供任何内容,则添加defaultProps (function-) 属性以设置默认值 109 | 110 | 这将在控制台中显示警告,因为customData应该是一个字符串 111 | 112 | 这将使用默认值 113 | 114 | ### Lesson 7 - Property Example 115 | 116 | 这是一个更实用的组件格式化日期并返回一个例子``包含格式化的字符串 117 | 118 | 还有一个更复杂的日期属性类型检查该属性是必需的,因为没有设置默认值 119 | 120 | 我们必须提供一个日期对象,组件进行格式化 121 | 122 | ### Lesson 8 - Nested Components 123 | 124 | 组件与元素一样可以嵌套 125 | 126 | 为此,子组件内部使用子属性 127 | 128 | 这个组件只是将它的孩子包裹在一个`
  • `元件 129 | 130 | 这个组件把它的孩子包装成一个`
      `元件 131 | 132 | 如果``没有孩子的时候会创建一个默认的孩子 133 | 134 | 现在我们渲染两个``没有和有物品 135 | 136 | ### Lesson 9 - Component Classes 137 | 138 | `React.createElement()`reateClass已从中删除`React`16现在是它自己的软件包 139 | 140 | 通常情况下,组件需要维护一些内部状态,例如,如果在这种情况下涉及交互,则组件功能不够,组件功能只能具有属性而没有状态,我们需要具有渲染功能的组件类 141 | 142 | 用于与组件函数相同的属性类型检查 143 | 144 | 此方法为缺少的属性设置默认值,它将被调用`React`在组件被装入DOM之前 145 | 146 | 这个方法为它将被调用的组件设置初始状态`React`如果缺少这种方法,组件被装入DOM之前,`this.state`将是未定义的 147 | 148 | 国家可以是任何`JavaScript`价值,往往是一个对象 149 | 150 | 此方法处理所有的点击``元件 151 | 152 | 可以使用包含新状态的对象调用setState () ,但通常会触发render () 的调用`React`可以批量多次调用并延迟render () 调用 (使调用异步) 为了防止出现这种情况,setState可以取回一个回调 153 | 154 | 如果我们依赖,这可能会导致意想不到的行为`this.state`要么`this.props`为我们的计算`this.setState` ({时间: `this.state.times`+ 1}) 155 | 156 | 回调版本没有这个问题回调得到正确的状态和`props`在更新时 157 | 158 | 这个方法会被调用`React`每次将组件装入DOM之后`this.setState` () 被称为它就像之前的组件函数,但没有`props`论据 159 | 160 | 使用该组件属性的创建者给出的道具现在处于`this.props`而不是`props`论据 161 | 162 | 通过点击处理程序返回一个元素`props`和状态值. 状态存储在`this.state` 163 | 164 | 创建一些具有默认颜色的交互式有状态组件类的实例一切与更简单的组件函数完全相同对于此组件的用户,接口没有改变 165 | 166 | ### Lesson 10 - Example App 167 | 168 | 一个简单的例子`React`应用程序它为无状态组件使用简单的组件函数,并使用复杂的组件类来处理交互 169 | 170 | 首先我们有任务和任务列表他们通过他们的属性获得他们所有的数据/状态`` 171 | `` 172 | `` 173 | `` 174 | 175 | 任务需要一个文本属性 176 | 177 | TaskList需要在其子属性中包含任务数组 178 | 179 | 打印第一个粗体元素 180 | 181 | 这个组件处理输入它需要是一个类,因为``元素是有状态的 182 | 183 | 当有人输入进来时被调用``元件 184 | 185 | 当有人点击时会被调用`