[React] React Fundamentals: with-addons - ReactLink
It can be tedious to type out all the boilerplate needed to get the DOM and states in React to synchronize. Luckily, React provides a version of the toolkit with a selection of available addons. This lesson is going to dig into ReactLink, and how this addon can give you two-way binding.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React Lesson 15: dynamically create componenets</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/JSXTransformer.js"></script>
<style>
body {
margin: 25px;
}
</style>
</head>
<body>
<div id="panel"></div>
<script type="text/jsx">
/** @jsx React.DOM */ var App = React.createClass({
getInitialState:function(){
return {
name: '',
email: ''
}
},
update: function () {
this.setState({
name: this.refs.name.getDOMNode().value,
email: this.refs.email.getDOMNode().value
})
},
render:function(){
return (
<form>
<div>
<input type="text" ref="name" onChange={this.update} placeholder="Name"/>
<label>*{this.state.name}*</label>
</div>
<div>
<input type="text" ref="email" onChange={this.update} placeholder="Email"/>
<label>*{this.state.email}*</label>
</div>
</form>
);
} }); React.render(<App />, document.getElementById('panel'));
</script>
</body>
</html>

Use addon: ReactLink
1. include the script:
script src="https://fb.me/react-with-addons-0.13.3.js"></script>
2. Add mixin:
mixins: [React.addons.LinkedStateMixin],
3. Use valueLink={this.linkState('name')} instead of 'ref' and 'onChange':
<input valueLink={this.linkState('name')} type="text" placeholder="Name" />
Code:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React Lesson 15: dynamically create componenets</title>
<script src="https://fb.me/react-with-addons-0.13.3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
<style>
body {
margin: 25px;
}
</style>
</head>
<body>
<div id="panel"></div>
<script type="text/jsx">
/** @jsx React.DOM */ var App = React.createClass({
mixins: [React.addons.LinkedStateMixin],
getInitialState:function(){
return {
name: '',
email: ''
}
},
render:function(){
return (
<form>
<div>
<input valueLink={this.linkState('name')} type="text" placeholder="Name" />
<label>*{this.state.name}*</label>
</div>
<div>
<input valueLink={this.linkState('email')} type="text" placeholder="Email" />
<label>*{this.state.email}*</label>
</div>
</form>
);
} }); React.render(<App />, document.getElementById('panel'));
</script>
</body>
</html>
[React] React Fundamentals: with-addons - ReactLink的更多相关文章
- [React] React Fundamentals: Integrating Components with D3 and AngularJS
		
Since React is only interested in the V (view) of MVC, it plays well with other toolkits and framewo ...
 - React/React Native 的ES5 ES6写法对照表
		
//es6与es5的区别很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends React.Component ...
 - React/React Native 的ES5 ES6写法对照表-b
		
很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends React.Component),然而网上搜到的很多教 ...
 - [React] react+redux+router+webpack+antd环境搭建一版
		
好久之前搭建的一个react执行环境,受历史影响是webpack3.10.0和webpack-dev-server2.7.1的环境,新项目准备用webpack4重新弄弄了,旧的记录就合并发布了(在没有 ...
 - React: React组件的生命周期
		
一.简介 在前面的第二篇博文中对组件的生命周期虽然做了一个大略介绍,但总感觉说的过于简单,毕竟生命周期是React组件的核心部分.在我们熟练使用React挂载和合成组件来创建应用表现层的过程中,针对数 ...
 - React: React的属性验证机制
		
一.简介 在开发中,属性变量类型的验证,几乎是任何语言都必须关注的问题,因为如果传入的数据类型不对,轻者程序运行仅仅是给出警告⚠️,严重的会直接导致程序中断,APP闪退或者web页面挂掉,这是很严重的 ...
 - React/react相关小结
		
React React组件由React元素组成,React组件使用React.Component或React.PureComponent来生成:React元素使用JSX的语法来编写或使用React.c ...
 - [React] React Fundamentals:  Add-on ClassSet() for ClassName
		
To get the add-ons, use react-with-addons.js (and its minified counterpart) rather than the common r ...
 - [React] React Fundamentals: Mixins
		
Mixins will allow you to apply behaviors to multiple React components. Components are the best way t ...
 
随机推荐
- InstallShield 创建自己的Dialog
			
1.在"User Interface"-"Dialogs"下,在All Dialogs右击"New Dialogs-"创建自己的Dialog ...
 - php简易计算器实例
			
<html> <head> <title>PHP实现简单计算器</title> <meta http-equiv="Content-Ty ...
 - Linux 多用户和多用户边界
			
1. 需求背景 2. 多用户的边界: 独立的工作目录 3. 多用户的边界:可操作/访问的资源 4. 多用户的边界: 可执行的操作 5. 多用户的特性标识: UID和GID -------------- ...
 - python【第十六篇】DOM
			
文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口. DOM可以以一种独立于平台和语言的方式访问和修改一个文档的内容和结构.换句 ...
 - Makefile的简单例子
			
1.生成test可执行文件,源文件有prog.c prog.h cord.h test:prog.o code.o gcc -o test prog.o code.o prog.o:prog.c pr ...
 - StartSSL免费SSL证书成功申请-HTTPS让访问网站更安全
			
StartSSL免费SSL证书成功申请-HTTPS让访问网站更安全 一.StartSSL个人证书登录申请 1.StartSSL官网: 1.官方首页:http://www.startssl.com/ 2 ...
 - Codeforces Round #206 (Div. 2)
			
只会做三个题: A:简单题,不解释: #include<cstdio> using namespace std; int k,d; int main() { scanf("%d% ...
 - Ubuntu版本介绍
			
转自Ubuntu版本介绍 经常有人问起Ubuntu的版本选择问题,论坛中虽有帖子提及,但不是很详细,不集中,我就尝试把Ubuntu上的这点东东翻译一下,供大家参考,水平有限,敬请包涵.指正. Ubu ...
 - codeforces C. Little Pony and Expected Maximum
			
题意:一个筛子有m个面,然后扔n次,求最大值的期望; 思路:最大值为1 有1种,2有2n-1种, 3有3n -2n 种 所以为m的时有mn -(m-1)n 种,所以分别求每一种的概率,然后乘以这 ...
 - 如何得到UBUNTU源代码
			
http://www.pleaseguide.me/367/how-to-get-the-source-code-of-ubuntu 在按书作测试,有难点一一解决. Ubuntu's Source c ...