[React] React Fundamentals: Accessing Child Properties
Jun 07, 2016 pm 03:38 PMWhen 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
?
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
?
<meta charset="UTF-8"> <title>React Lesson 6: Accessing Child Properties</title> <link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.min.css"> <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>* @jsx React.DOM <span>*/ <span>var App =<span> React.createClass({ render: <span>function<span>(){ <span>return<span> ( <BButton>I <BHeart> React<span> ); } }); <span>var BButton =<span> React.createClass({ render: <span>function<span>() { <span>return<span> ( <a className="btn btn-primary">{<span>this.props.children} <span> ); } }); <span>var BHeart =<span> React.createClass({ render:<span>function<span>(){ <span>return <span className="glyphicon glyphicon-heart"> <span> } }); React.render(<App />, document.body); </script>
?
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'.

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Vue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.

Netflixusesacustomframeworkcalled"Gibbon"builtonReact,notReactorVuedirectly.1)TeamExperience:Choosebasedonfamiliarity.2)ProjectComplexity:Vueforsimplerprojects,Reactforcomplexones.3)CustomizationNeeds:Reactoffersmoreflexibility.4)Ecosystema

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

The React ecosystem includes state management libraries (such as Redux), routing libraries (such as ReactRouter), UI component libraries (such as Material-UI), testing tools (such as Jest), and building tools (such as Webpack). These tools work together to help developers develop and maintain applications efficiently, improve code quality and development efficiency.

Netflix uses React as its front-end framework. 1) React's componentized development model and strong ecosystem are the main reasons why Netflix chose it. 2) Through componentization, Netflix splits complex interfaces into manageable chunks such as video players, recommendation lists and user comments. 3) React's virtual DOM and component life cycle optimizes rendering efficiency and user interaction management.

React is a JavaScript library developed by Meta for building user interfaces, with its core being component development and virtual DOM technology. 1. Component and state management: React manages state through components (functions or classes) and Hooks (such as useState), improving code reusability and maintenance. 2. Virtual DOM and performance optimization: Through virtual DOM, React efficiently updates the real DOM to improve performance. 3. Life cycle and Hooks: Hooks (such as useEffect) allow function components to manage life cycles and perform side-effect operations. 4. Usage example: From basic HelloWorld components to advanced global state management (useContext and

The main reasons for MySQL installation failure are: 1. Permission issues, you need to run as an administrator or use the sudo command; 2. Dependencies are missing, and you need to install relevant development packages; 3. Port conflicts, you need to close the program that occupies port 3306 or modify the configuration file; 4. The installation package is corrupt, you need to download and verify the integrity; 5. The environment variable is incorrectly configured, and the environment variables must be correctly configured according to the operating system. Solve these problems and carefully check each step to successfully install MySQL.

React's future will focus on the ultimate in component development, performance optimization and deep integration with other technology stacks. 1) React will further simplify the creation and management of components and promote the ultimate in component development. 2) Performance optimization will become the focus, especially in large applications. 3) React will be deeply integrated with technologies such as GraphQL and TypeScript to improve the development experience.
