The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Access Nested Data with Reacts props.children

Access Nested Data with Reacts props.children

1:33
When you're building your React components, you'll probably want to access child properties of the markup. `this.props.children` accesses the innerHTML or nested components of another component.
Watch this lesson now
Avatar
egghead.io

When you're building your React components, you'll probably want to access child properties of the markup.

Avatar
Ryan

HI I was having trouble using the React.renderComponent( ) method from the example, and it looks like the React team has changed the method that you should use in this case from React.renderComponent() to React.render()......https://medium.com/@_jh3y/adopting-change-with-react-v0-12-1d9625e27535

Avatar
Ryan

Hey how did you use the emmet like syntax when typing the span.glyphicon... and have webstorm know to use className instead of class (JSX vs HTML) ?

Avatar
Ryan

Hey how did you use the emmet like syntax when typing the span.glyphicon... and have webstorm know to use className instead of class (JSX vs HTML) ?

Avatar
Kevin

How do I setup bootstrap in my app? The video didn't show this...

Avatar
Joseph

Just add <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> to your index.html.

In reply to Kevin
Avatar
Somsubhra

Really Nice Video..Have been enjoying the series

Also found that the Button could be created in a functional(presentational) way

const Button = (props) => <button>{props.children}</button>
In reply to Joseph
Avatar
Olga

I'm still having trouble understanding this.props.children. When adding {this.props.children} to the child component, why doesn't it render a second button with the parent's information ?So in total there would be two buttons. I know my logic is wrong, but can someone tell me why this isn't the case ?

Avatar
Kirk Sefchik

I'm still having trouble understanding this.props.children. When adding {this.props.children} to the child component, why doesn't it render a second button with the parent's information ?So in total there would be two buttons. I know my logic is wrong, but can someone tell me why this isn't the case ?

I think I understand where you're coming from. The nomenclature here is very confusing -- it tripped me up as well. this in the Button class is indeed referring to Button (not <button> directly, but by extension). Whenever you pass something into the inner HTML of a component, it's populated in [child].props.children. If you install React Dev Tools for your browser (or console.dir(this) inside Button.render() { ... }...), you can see that Button.children is an array composed of 3 "children" passed to it by the App component: "I ", <Heart/> and " React". I know, silly right? They need to come up with a better name for this -- I don't know why they couldn't just call it [child].props.innerHTML. Regardless, I think that answers your question. :D

In reply to Olga
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?