React Core Features

Here is a summary of the core features. We will cover each feature in detail throughout the examples.

JSX (JavaScript Syntax Extension)

  1. JSX has a concise and familiar syntax for defining tree structures with attributes
  2. JSX syntax needs to be transpiled to JavaScript (i.e. by Babel)
  3. In contrast to JavaScript, JSX is statically-typed
  4. JSX uses ES6 classes, which are similar to Java

One-way data flow

  1. Properties are passed by the parent component to the child components
  2. The properties are treated as immutable values
  3. Child components should never directly modify any properties that are passed to them
  4. PropTypes can be used for defining the type of each property that is passed to a given component. If a component receives an invalid value for a property, there will be a warning in the console. PropTypes are checked during runtime

Virtual DOM

  1. React uses the Virtual DOM to create an in-memory copy of the browsers DOM
  2. When changing the state of components, React updates the virtual DOM first
  3. After that it computes the resulting differences, and updates the browser’s displayed DOM efficiently

Lifecycle methods

These methods can be overridden for each component, to run code during a specific lifecycle phase.

  1. Mounting:

    • constructor()
    • componentWillMount()
    • render()
    • componentDidMount()
  2. Updating:
    • componentWillReceiveProps()
    • shouldComponentUpdate()
    • componentWillUpdate()
    • render()
    • componentDidUpdate()
  3. Unmounting:
    • componentWillUnmount()
  4. Error handling (since React 16 – released September 2017):
    • componentDidCatch()

We will explain these core features in more detail with a couple of code snippets in the next section.

Babel (ES5, ES6)

The JavaScript syntax that you will see in our examples is ECMAScript 6 (ES6) notation. If you need to run your web app inside older web browsers, you can use Babel (https://babeljs.io/) to transpile ES6 code to ES5. Here is an example how babel will transpile the ES6 arrow function to a regular ES5 function.

ES6 syntax Transpiled to ES5 syntax
[1,2,3,4].map(n => n + 1);
[1,2,3,4].map(
function(n) {
return n + 1;
}
);

https://blog.codecentric.de/en/2017/11/developing-modern-offline-apps-reactjs-redux-electron-part-2-reactjs-basics/

最新文章

  1. 【翻译】CEDEC2015 速成Albedo Chart 制作
  2. 【工具推荐】ELMAH——可插拔错误日志工具
  3. vi 常用命令行
  4. H264编码参数的一些小细节
  5. 尝试设计LFSR加密器,并用CAP4验证随机性
  6. 工作总结之动画与VR
  7. Swift - 使用CABasicAnimation实现动画效果
  8. sprintf格式化字符串带来的注入隐患
  9. BZOJ_2049_[Sdoi2008]Cave 洞穴勘测_LCT
  10. 工厂方法模式--java代码实现
  11. .net mvc + layui做图片上传(一)
  12. 107个JS常用方法(持续更新中)
  13. 洛谷P3242 接水果
  14. 完成将 toChineseNum, 可以将数字转换成中文大写的表示,处理到万级别,例如 toChineseNum(12345),返回 一万二千三百四十五
  15. 用Django ORM实现树状结构
  16. PEP 8 - Python代码样式指南
  17. java.lang.verifyerror:bad type on orerand stack
  18. 【转】C++ 枚举类型的思考
  19. 【bzoj4484】【jsoi2015】最小表示
  20. TP框架M方法 create方法丢失字段问题

热门文章

  1. linux -------- 使用xshell ,winscp 连接linux 以及一些问题解决
  2. windows下elasticsearch安装ik分词器后无法启动
  3. [转帖]来聊聊,华为与H3C(华三)的前世今生!
  4. [转帖]B4. Concurrent JVM 锁机制(synchronized)
  5. 数据库权限优化,权限设计BigInteger
  6. HashSet去重
  7. 封装:Cmd命令调用和常用命令
  8. C#读写设置修改调整UVC摄像头画面-倾斜
  9. 【真】CSP2019退役记(upd:12.21)
  10. 连接池未注册org.logicalcobwebs.proxool.ProxoolException: Attempt to refer to a unregistered pool by its alias 'XXX'