[React] React Fundamentals: Accessing Child Properties
When you're building your React components, you'll probably want to access child properties of the markup.
Parent can read its children by accessing the special this.props.children prop.this.props.children is an opaque data structure: use the React.Children utilities to manipulate them.
https://facebook.github.io/react/docs/multiple-components.html
this.props.children undefined
You can't access the children of your component through this.props.children.this.props.children designates the children being passed onto you by the owner.
https://facebook.github.io/react/tips/children-undefined.html
Type of the Children props
Usually, a component's children (this.props.children) is an array of components. However, when there is only a single child, this.props.children will be the single child component itself without the array wrapper. This saves an array allocation.
https://facebook.github.io/react/tips/children-props-type.html

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>React Lesson 6: Accessing Child Properties</title>
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.min.css"/>
</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">
/** @jsx React.DOM */ var App = React.createClass({
render: function(){
return (
<BButton>I <BHeart></BHeart> React</BButton>
);
}
}); var BButton = React.createClass({
render: function() {
return (
<a className="btn btn-primary">{this.props.children}</a>
);
}
}); var BHeart =
React.createClass({
render:function(){
return <span className="glyphicon glyphicon-heart"></span>
}
}); React.render(<App />, document.body);
</script>
</body>
</html>
App has two children BButton and BHeart, all thoes chilren come thought from {this.props.children}.
If you don't have {this.props.children}:
var BButton = React.createClass({
render: function() {
return (
<a className="btn btn-primary">No passed in!</a>
);
}
});
We end up with this: 
[Notice:] Just remeber when give class to the render elements, we need to use 'className' not 'class'.
[React] React Fundamentals: Accessing Child Properties的更多相关文章
- [React Fundamentals] Accessing Child Properties
When you're building your React components, you'll probably want to access child properties of the m ...
- [React] React Fundamentals: transferPropsTo
the transferPropsTo method lets you easily push properties into your components to easily customize ...
- [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 ...
随机推荐
- SQLite Version3.3.6源代码文件结构
Version 3.3.6源代码文件结构 ——整理:hustcat 2009-2-19 文件名称 大小by ...
- C#博文搜集
1. abstract (抽象类) 参考1 2. interface (接口) 参考1 3. 委托 C#委托学习
- 乐1/MACBOOK/ N1 Type-C接口新体验
经过在华强北电子市场排队一个小时,笔者顺利买到了期待已久的乐1,结合之前的NOKIA平板电脑N1,苹果全新MACBOOK,终于集齐了手机.平板.笔记本电脑三种TYPE-C接口设备(能兑换极品装备吗?^ ...
- 这些小众软件让你的效率提升N倍!(必备,收藏)
大部分的我们,电脑买来之后,软件越装越多,电脑越来越卡,导致工作的效率也是越来越低. 同时还可能长期处于软件安装完又卸载的无限恶性循环中.提高工作效率是我们利用电脑办公的一大优势,安装好的软件更是可以 ...
- Visual Assist X
老师推荐的一款vc++6.0插件 visual assistx_百度百科 http://baike.baidu.com/view/4439152.htm?fr=aladdin 下载 VC++6.0助手 ...
- Android Binder设计与实现 - 设计篇
要 Binder是Android系统进程间通信(IPC)方式之一.Linux已经拥有管道,system V IPC,socket等IPC手段,却还要倚赖Binder来实现进程间通信,说明Binder具 ...
- Introducing RecyclerView(二)
文/poberWong(简书作者)原文链接:http://www.jianshu.com/p/7fdfea845937著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 正文: Recyc ...
- Android java.net.SocketException四大异常解决方案
java.net.SocketException如何才能更好的使用呢?这个就需要我们先要了解有关这个语言的相关问题.希望大家有所帮助.那么我们就来看看有关java.net.SocketExceptio ...
- 解决在IE里预览时弹出:为了有利于保护安全性......
用Dreamweaver做网页,在IE里预览时弹出这个:为了有利于保护安全性,Internet Explorer 已限制此网页运行可以访问计算机的脚本或ActiveX控件. 在页面顶部加段代码就可以了 ...
- GridView導出Excel 解決亂碼問題
Response.Clear(); Response.Charset = "gb2312"; Response.Buffer = true; Response.AddHeader( ...