React(JSX语法)----动态UI
1.React honws how to bubble and capture events according to the spec,and events passed to your event handler are guaraneed to be condidtent with the W3C spec,regardless of which brower you're using.
if you'd like to use React a couch device such as a phone or tablet,simply call React.initialzeTouchEvents(true);to enable touch event handing.
2.Autobinding and Event Delegation
Autobinging:With React,every method is automatically bound to its component instance.React caches the bound method such that id's extremely CPU and memory efficient.It's also less typing.
Event delegation:React doesn't actually attach event handlers to the nodes themselves. When React starts up, it starts listening for all events at the top level using a single event listener. When a component is mounted or unmounted, the event handlers are simply added or removed from an internal mapping. When an event occurs, React knows how to dispatch it using this mapping. When there are no event handlers left in the mapping, React's event handlers are simple no-ops. To learn more about why this is fast, see David Walsh's excellent blog post.
3.Components are Just State Machines:
In React,you simply update a component's state,and then render a new UI based on this new state.React tabkes care of updating the DOM for you in the most efficient way.
4.State work
A common way to inform React of a data change is by calling setState(data, callback)
. This method merges data
into this.state
and re-renders the component. When the component finishes re-rendering, the optional callback
is called. Most of the time you'll never need to provide a callback
since React will take care of keeping your UI up-to-date for you
5.What component should have state
A common pattern is to create several stateless components that just render data, and have a stateful component above them in the hierarchy that passes its state to its children viaprops
. The stateful component encapsulates all of the interaction logic, while the stateless components take care of rendering data in a declarative way.
6.waht should go in State
State should contain data that a component's event handlers may change to trigger a UI update.
7.What should'd go in state
this.state
should only contain the minimal amount of data needed to represent your UI's state. As such, it should not contain:
- Computed data: Don't worry about precomputing values based on state — it's easier to ensure that your UI is consistent if you do all computation within
render()
. For example, if you have an array of list items in state and you want to render the count as a string, simply renderthis.state.listItems.length + ' list items'
in yourrender()
method rather than storing it on state. - React components: Build them in
render()
based on underlying props and state. - Duplicated data from props: Try to use props as the source of truth where possible. One valid use to store props in state is to be able to know it's previous values, because props can change over time.
React(JSX语法)----动态UI的更多相关文章
- React JSX语法说明
原文:http://my.oschina.net/leogao0816/blog/379487 什么是JSX? 在用React写组件的时候,通常会用到JSX语法,粗看上去,像是在Javascript代 ...
- 2. React JSX语法及特点介绍
什么是JSX JSX 是一种类 XML 语言,全称是 JavaScript XML .React 可以不使用 JSX来编写组件,但是使用JSX可以让代码可读性更高.语义更清晰.对 Re ...
- React(JSX语法)-----JSX基本语法
JSX------HTML tags vs React Components: 1.To render a html tag,just use lower-case tag names in JSX; ...
- 学习 React(jsx语法) + es2015 + babel + webpack
视频学习地址: http://www.jtthink.com/course/play/575 官方地址 https://facebook.github.io/react/ 神坑: 1.每次this.s ...
- React(JSX语法)----JSX拼写
注意:For DOM differences,such as the inline style attribute,check here. // bad: it displays "FIrs ...
- React(JSX语法)-----JSX属性
1. if you know all the propertities that you want to place on a component ahead of time,it is easy t ...
- 22-React JSX语法
React JSX语法 JSX只是一个语法糖,每一个XML标签都会被JSX转换工具转换成纯Javascript代码,当然你想直接使用纯Javascript代码写也是可以的,只是利用JSX,组件的结构和 ...
- react实战项目开发(2) react几个重要概念以及JSX语法
前言 前面我们已经学习了利用官方脚手架搭建一套可以应用在生产环境下的React开发环境.那么今天这篇文章主要先了解几个react重要的概念,以及讲解本文的重要知识JSX语法 React重要概念 [思想 ...
- React高级教程(es6)——(1)JSX语法深入理解
从根本上来说,JSX语法提供了一种创建React元素的语法糖,JSX语句可以编译成: React.createElement(component, props, …children)的形式,比如: & ...
随机推荐
- JS日期类型处理
Date 操作日期和时间的对象 Date.getDate( ) 返回一个月中的某一天 Date.getDay( ) 返回一周中的某一天 Date.getFullYear( ) 返回Date对象的年份字 ...
- Python3学习(二)-递归函数、高级特性、切片
##import sys ##sys.setrecursionlimit(1000) ###关键字参数(**关键字参数名) ###与可变参数不同的是,关键字参数可以在调用函数时,传入带有参数名的参数, ...
- powershell玩转SQL SERVER所有版本
微软发布了最新的powershell for sql server 2016命令行客户端库.文章介绍了与之相关的实用方法. powershell 传教士 原创文章 2016-06-05, 2016-1 ...
- 黑马程序员——C语言基础 变量类型 结构体
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) (一)变量类型 1)局部变量 1> 定义:在函数内部定义的变量,称为 ...
- Percona Server 5.6.33-79.0 发布
Percona Server 5.6.33-79.0 发布了,该版本基于 MySQL 5.6.33,包含了所有的 bug 修复,是Percona Server 5.6 系列中的正式版本.该版本主要是修 ...
- python-phpbb3 (可以用python3 操作 phpbb3 论坛的模块)
python-phpbb3 2016年8月30日 04:50:48 codegay phpbb3是PHP写的开源的论坛,python-phpbb3这个项目是用python3实现很多对phpbb3论坛操 ...
- GoldenGate针对OEM 13.1的版本发布
OGG 针对OEM(Oracle Enterprise Manager) 13.1的插件已经可以从这里下载: http://www.oracle.com/technetwork/middleware/ ...
- Python的平凡之路(18)
一.JS 正则部分 test - 判断字符串是否符合规定的正则rep = /\d+/;rep.test("asdfoiklfasdf89asdfasdf")# truerep ...
- iOS系统tabbar图标出现重影问题
大家在自定义tabbar的时候会将系统的tabbar干掉,然后放上自已自定义的tabbar(含有想要的Button)对不对,具体代码如下: /** * 添加自定义的tabBar */ -(void)a ...
- ThinkPHP学习遇到的点问题(学习中,持续更新)
1.__ROOT__变量没有值的问题 今天遇到这个比较变态的问题,可能是我技术比较菜吧,搞了一个多小时,最后发现问题可能出现在 入口文件中定义的APP_NAME的名字和项目的跟目录名称相同了,比如我网 ...