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
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
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
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"> <span>/*</span><span>* @jsx React.DOM </span><span>*/</span> <span>var</span> App =<span> React.createClass({ render: </span><span>function</span><span>(){ </span><span>return</span><span> ( </span><BButton>I <BHeart></BHeart> React</BButton><span> ); } }); </span><span>var</span> BButton =<span> React.createClass({ render: </span><span>function</span><span>() { </span><span>return</span><span> ( </span><a className="btn btn-primary">{<span>this</span>.props.children}</a> <span> ); } }); </span><span>var</span> BHeart =<span> React.createClass({ render:</span><span>function</span><span>(){ </span><span>return</span> <span className="glyphicon glyphicon-heart"></span> <span> } }); React.render(</span><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}:
<span>var</span> BButton =<span> React.createClass({ render: </span><span>function</span><span>() { </span><span>return</span><span> ( </span><a className="btn btn-primary">No passed <span>in</span>!</a> <span> ); } });</span>
We end up with this:
[Notice:] Just remeber when give class to the render elements, we need to use 'className' not 'class'.
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号