├── LICENSE ├── README.md ├── docs ├── 00-object-elements.html ├── 01-element-factory.html ├── 02-jsx.html ├── 03-nested-elements.html ├── 04-components.html ├── 05-properties.html ├── 06-property-types.html ├── 07-property-example.html ├── 08-nested-components.html ├── 09-component-classes.html ├── 10-example-app.html ├── 11-lifecycle-methods.html ├── 12-component-refactor.html ├── 13-element-refactor.html ├── 14-references.html ├── 15-simple-integration.html └── 16-advanced-integration.html ├── summary.md └── summary.zh.md /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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/01-element-factory.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 01 Element Factory - React From Zero 4 | 5 | 6 | 7 | 8 |
9 | 10 | -------------------------------------------------------------------------------- /docs/02-jsx.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 02 JSX - React From Zero 4 | 5 | 6 | 7 | 8 | 14 | 15 |
16 | 17 | -------------------------------------------------------------------------------- /docs/03-nested-elements.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 03 Nested Elements - React From Zero 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 58 | -------------------------------------------------------------------------------- /docs/04-components.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 04 Components - React From Zero 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 79 | -------------------------------------------------------------------------------- /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/07-property-example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 07 Property Example - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 37 | -------------------------------------------------------------------------------- /docs/08-nested-components.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 08 Nested Components - React From Zero 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | -------------------------------------------------------------------------------- /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/10-example-app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 Example App - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 129 | -------------------------------------------------------------------------------- /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/12-component-refactor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 Component Refactor - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /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/14-references.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 References - React From Zero 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /summary.md: -------------------------------------------------------------------------------- 1 | ## menu 2 | 3 | ### Lesson 0 - Object Elements 4 | 5 | `React` uses `ES2015` Symbols to `"tag"` its element-objects. 6 | 7 | It uses a magic number as fallback on older browsers. 8 | 9 | `React` uses virtual `DOM` elements, which become real `DOM` elements on a render. 10 | 11 | A virtual `DOM` element can be defined as a simple object literal. 12 | 13 | Normally you would use the `React`. 14 | `createElement()` to create an element. 15 | 16 | This is what the return value of a `React`. 17 | `createElement()` call could look like. 18 | 19 | This special property will be checked by `React` to ensure this object 20 | is a `React` element and not just some user data 21 | `React.createElement()` sets it for you 22 | 23 | This will also be checked by `React`. 24 | 25 | We will be talking about references 26 | later, but if you're not using them, this has to be set to null and not 27 | undefined 28 | 29 | This defines the HTML-tag 30 | 31 | This defines the properties that get passed down into the element 32 | 33 | In this example there is just a single text node as child 34 | a `CSS` class 35 | 36 | styles can be passed as object literals 37 | `React` uses camelCase instead of dashed-case (like `CSS/D3` do) 38 | 39 | event handlers can be added as properties, too 40 | `React` uses synthetic events, which basically try to normalize browser behaviour 41 | 42 | another element that doesn"t have much configuration 43 | `React` needs a `DOM` element as render target 44 | 45 | `ReactDOM`OM is responsible for inserting the element into the DOM 46 | 47 | ### Lesson 1 - Element Factory 48 | 49 | `React.createElement()` needs type, properties, children. 50 | This is less verbose than using plain object literals, 51 | it hides the $$type/Symbol and ref mentioned in lesson 0 52 | 53 | The second argument is the property object and has to be null if empty 54 | 55 | ### Lesson 2 - `JSX` 56 | 57 | Now we will use `JSX`, which needs to be converted to `JavaScript`. 58 | For this we will use `Babel`. `Babel` is normally used to convert `ES2015` to `ES5`, but 59 | it also can convert `JSX` to `ES5`. `Babel`s browser version uses text/babel script tags. 60 | 61 | `JSX` is the idiomatic way of creating elements. 62 | It's basically `XHTML` with `{}` for dynamic content 63 | also class has to be called className 64 | 65 | Is the same as 66 | 67 | `JSX` shines especially with simple elements that make up the majority 68 | 69 | Is the same as 70 | 71 | As we can see, everything else works as before 72 | 73 | ### Lesson 3 - Nested Elements 74 | 75 | Elements can be nested, which will result in nested `React.createElement()`reateElement calls 76 | As you can imagine, writing this without `JSX` would be pretty tedious 77 | 78 | they can also, like mentioned in lesson 2, contain `JavaScript` in `{}` 79 | 80 | `JavaScript` insertion has the same syntax in attributes as in normal text or elements 81 | 82 | this `JavaScript` can contain elements too 83 | it is also possible to "spread" an object as properties 84 | 85 | ### Lesson 4 - Components 86 | 87 | The main selling point of `React` is its component system 88 | components are used to encapsulate elements and their behaviour 89 | see them as a mix of controller and view of MVC 90 | 91 | Here we use stand alone elements and some data 92 | 93 | Here the elements are encapsuled in a simple component function 94 | They have to start with a capital letter and 95 | return exactly ONE root element with or without nested elements (before `React` 16) 96 | 97 | Since `React` 16.0.0, components can return an array of elements as well 98 | In doing so, no additional wrapper element is created. 99 | One caveat is that, similarly to what we do when rendering an array, 100 | we have to add a unique key to each element in the array 101 | (we'll see more on this in the next lesson) 102 | 103 | Since `React` 16.2.0, we can use special "wrapper" components called fragments 104 | that behave the same (no extra wrapper element created) 105 | but remove the need to explitly set keys (fragments do this under the hood) 106 | 107 | a component function can be used like an element 108 | 109 | this translates to a `React.createElement()` call 110 | the null indicates that no properties have been set 111 | 112 | for reference a `React`-internal `
` tag 113 | 114 | gets converted to 115 | 116 | ### Lesson 5 - Properties 117 | 118 | Components, like elements, can use properties, too 119 | 120 | Which also works with an object and the spread (...) operator 121 | 122 | This allows components with dynamic content 123 | 124 | If an array is used as "child node" each child needs a unique key-property 125 | 126 | ### Lesson 6 - Property Types 127 | 128 | PropTypes were removed from `React` 16 and are now their own package 129 | 130 | Components get created to encapsulate stuff that should be together in one 131 | place and for reuse. 132 | Reuse requires the user of the component to supply the correct properties so 133 | we can define a type of each property and set defaults 134 | 135 | Add the propTypes (function-)property to the component function 136 | to let it validate its (element-)properties 137 | 138 | `React` supplies us with a bunch of types, like string 139 | 140 | Add defaultProps (function-)property to set the defaults 141 | if nothing was provided by the user 142 | 143 | This will show a warning in the console, because customData should be a string 144 | 145 | This will use the defaults 146 | 147 | ### Lesson 7 - Property Example 148 | 149 | Here's a more practical example of a component 150 | it formats a date and returns a `` containing that formatted string 151 | 152 | Also a more sophisticated type check for the date property 153 | The property is required, because there are no defaults set 154 | 155 | We have to supply a date object and the component does the formatting 156 | 157 | ### Lesson 8 - Nested Components 158 | 159 | Components, like elements, can be nested 160 | 161 | for this, the children property is used inside the component 162 | 163 | This component just wraps its children in an `
  • ` element 164 | 165 | This component wraps its children into an `
      ` element 166 | 167 | If the `` is created without children it gets a default child 168 | 169 | now we render two ``s, without and with Items 170 | 171 | ### Lesson 9 - Component Classes 172 | 173 | `React.createElement()`reateClass was removed from `React` 16 and is now its own package 174 | 175 | Often a component needs to maintain some internal state 176 | for example if there is an interaction involved 177 | in this case a component function is not sufficient 178 | the component function can only have properties and no state 179 | we need a component class with a render function 180 | 181 | used for type-checking of the properties 182 | same as with the component function 183 | 184 | this method sets default values for missing properties 185 | it will be called by `React` 186 | before the components gets mounted into the DOM 187 | 188 | this method sets the initial state for the component 189 | it will be called by `React` 190 | before the components gets mounted into the DOM 191 | if this method is missing, `this.state` will be undefined 192 | 193 | The state can be any `JavaScript` value, often it is an object 194 | 195 | this method handles all the clicks on the `` element 196 | 197 | setState() can be called with an object that contains the new state 198 | normally this triggers a call of render(), but `React` can batch multiple 199 | calls and defer the render() call (make the call asynchronous) 200 | To prevent this, setState can take a callback instead 201 | 202 | This can lead to unexpected behaviour, if we rely on `this.state` or 203 | `this.props` for our calculations 204 | `this.setState`({times: `this.state.times` + 1}) 205 | 206 | The callback version doesn't have this problem 207 | The callback gets the right state and `props` at time of the update 208 | 209 | this method will be called by `React` 210 | after the component got mounted into the DOM 211 | also every time `this.setState`() was called 212 | it's like the component function from before 213 | but without a `props` argument 214 | 215 | using the prop given by the creator of this component 216 | properties are now in `this.props` instead of the `props` argument 217 | 218 | returning an element with a click-handler and the `props` and 219 | state values. state is stored in `this.state` 220 | 221 | creating some instances of the interactive stateful component class 222 | one with default color 223 | Everything works exactly like with the simpler component functions 224 | The interface has not changed for the user of this component 225 | 226 | ### Lesson 10 - Example App 227 | 228 | An example of a simple `React` app 229 | It uses simple component functions for its stateless components 230 | and a complex component class to handle the interactions 231 | 232 | First we have the Task and TaskList 233 | They get all their data/state through their properties 234 | `` 235 | `` 236 | `` 237 | `` 238 | 239 | Task needs a text property 240 | 241 | TaskList needs an array of Task in its children property 242 | 243 | Print the first element bold 244 | 245 | This component handles the input 246 | It needs to be a class, because the `` element is stateful 247 | 248 | gets called when someone types into the `` element 249 | 250 | gets called when someone clicks the `