[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 ...
随机推荐
- scrollView and tableView
As we all know, tableView is the subclass of scrollView, tableView has every properties that scroll ...
- div+css知识点(2)
文字溢出 显示省略号的 关键的三句代码text-overflow:ellipsis; -o-text-overflow:ellipsis; overflow:hidden;文字缩进的代码是什么text ...
- go 语言与循环
package main import "fmt" type Employee struct{name string; age int} func displayName(e *E ...
- bzoj 1096: [ZJOI2007]仓库建设 斜率優化
1096: [ZJOI2007]仓库建设 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2242 Solved: 925[Submit][Statu ...
- matlab在图片上画框
matlab在图片上画框 之前写过一个MATLAB在图片上画框的代码, http://blog.csdn.net/carson2005/article/details/17262811 最近使用后发现 ...
- jQuery EasyUI parser 的使用场景
转自原文地址:http://www.easyui.info/archives/216.html parser,故名意思,就是解析器的意思,别看他只有那么几行代码,jQuery Easyui 能够根据c ...
- 7.微软AJAX的解决方案
Asp.net中内置的简化AJAX开发的控件UpdatePanel非常方便,但是它会带了许多viewstate,所以高手们并不喜欢它.但它开发在内网应用时可以考滤 放入ScriptManager,将要 ...
- 如何快速使用ECharts绘制可视化图表
1.在ECharts官网,下载ECharts的源码和示例文件. 2.解压缩下载下来的Echars压缩包,找到doc\example\www\echartsjs目录,将里面的js文件全部取出来,放到项目 ...
- 【POJ】2828 Buy Tickets
线段树+逆序插入. #include <stdio.h> #include <string.h> #define MAXN 200005 #define lson l, mid ...
- 【HDOJ】1606 Excuses, Excuses!
简单字符串. #include <cstdio> #include <cstring> #define MAXLEN 105 #define MAXN 25 char keys ...