[React] React Fundamentals: Owner Ownee Relationship
The owner-ownee relationship is used to designate a parent-child relationship with React components as it differs from the DOM relationship.
When one component renders another component, this is what React refers to as the "owner-ownee relationship," where the parent component is also called a "composite component."
We are going to create a component call 'Widget' which will be used inside our 'React_app' component.
'Widget' doesn't have any state, all it has is from 'React_app' pass into it.
<Widget update={this.myUpdate} name={this.state.name}></Widget>
Example:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>React Lesson 4: Onwer - Ownee</title>
</head>
<body> <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>
<script type="text/jsx"> var React_app = React.createClass({
getInitialState: function() {
return {
name: "Joe"
}
},
myUpdate: function(e){
this.replaceState({name: e.target.value});
},
render: function() {
return (
<div>
<Widget update={this.myUpdate} name={this.state.name}></Widget>
<Widget update={this.myUpdate} name={this.state.name}></Widget>
<Widget update={this.myUpdate} name={this.state.name}></Widget>
<Widget update={this.myUpdate} name={this.state.name}></Widget>
<Widget update={this.myUpdate} name={this.state.name}></Widget>
</div>
);
}
}); var Widget = React.createClass({
render: function(){
return (
<div>
Your name: <input type="text" onChange={this.props.update}/>
<h1>{this.props.name}</h1>
</div>
)
}
}); React.render(<React_app />, document.body);
</script>
</body>
</html>
[React] React Fundamentals: Owner Ownee Relationship的更多相关文章
- [React Fundamentals] Owner Ownee Relationship
The owner-ownee relationship is used to designate a parent-child relationship with React components ...
- [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: Accessing Child Properties
When you're building your React components, you'll probably want to access child properties of the m ...
随机推荐
- Memcached总结二:Memcached环境安装设置以及连接memcache服务器
1 在Ubuntu上安装Memcached 要在Ubuntu上安装Memcached,打开终端,然后输入以下命令: $sudo apt-get update $sudo apt-get install ...
- 奇怪的JS
有的时候发现JS是一门很高深的语言,不是我等俗人可以学会,没有private,没有public不说,居然连Class都没有,这个世界就是这样,有的东西你不一定非要想通,也不一定非要剖根问底,有的时候你 ...
- Ember.js demo1
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1 ...
- HDU 2493 Timer 数学(二分+积分)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2493 题意:给你一个圆锥,水平放置,圆锥中心轴与地面平行,将圆锥装满水,在圆锥某一表面开一个小洞,流出来 ...
- Android fragment 回调函数改进
由于fragment的onResume()等回调的调用时机与Activity不一样,导致用起来比较麻烦,所以我重新封装了一下回调函数,十分简单. 使用时只需要继承此基类,使用onFragmentXXX ...
- C#中如何生成矢量图
主要的功能就是使用C#画矢量图,然后导出到Word.Excel.Powerpoint中,并且能够再次被编辑.以下是解决过程: 首先应该确定在Office文档中可编辑图形使用的格式:学习了相关资料,了解 ...
- 转自作者:phylips@bmy
差分约束系统 2008-11-28 20:53:25| 分类: 算法与acm|举报|字号 订阅 出处:http://duanple.blog.163.com/blog/static/7097 ...
- .net文件压缩和解压及中文文件夹名称乱码问题
/**************************注释区域内为引用http://www.cnblogs.com/zhaozhan/archive/2012/05/28/2520701.html的博 ...
- 使用Chrome测试页面响应性
如今我们都知道 响应式 的意思.作为开发者,我们常常开发一些响应式的应用.有很多工具可以帮助我们完成这个目的.某些人甚至使用付费扩展.然而,我用了一个东西,它就是 Google Chrome 浏览器. ...
- 在 ASP.NET MVC Web 应用程序中输出 RSS Feeds
RSS全称Really Simple Syndication.一些更新频率较高的网站可以通过RSS让订阅者快速获取更新信息.RSS文档需遵守XML规范的,其中必需包含标题.链接.描述信息,还可以包含发 ...