Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialoliverchou
20,886 PointsWhat does {props.children} mean in this case?
In the video, we can see that the value of <input> and return <span> are altered to {props.children}
Guest.js
2 import React from 'react';
1 import PropTypes from 'prop-types';
3 import GuestName from './GuestName';
1
2 const Guest = props => (
3 <li>
4 ¦ <GuestName
5 ¦ ¦ isEditting={props.isEditting}
6 ¦ ¦ handleNameEdits={e => props.setName(e.target.value)}>
7 ¦ ¦ {props.name}
8 ¦ </GuestName>
9 ¦ <label>
10 ¦ ¦ <input
11 ¦ ¦ ¦ type="checkbox"
12 ¦ ¦ ¦ checked={props.isConfirmed}
13 ¦ ¦ ¦ onChange={props.handleConfirmation}
14 ¦ ¦ />
15 ¦ ¦ Confirmed
16 ¦ </label>
17 <button onClick={props.handleToggleEditting}>
18 {props.isEditting? "save": "edit"}
19 </button>
20 ¦ <button>remove</button>
21 </li>
22 );
23
24 Guest.propTypes = {
25 name: PropTypes.string,
26 isConfirmed: PropTypes.bool.isRequired,
GuestName.js
1 import React from 'react';
1 import PropTypes from 'prop-types';
2
3 const GuestName = props => {
4 if (props.isEditting) {
5 ¦ return (
6 ¦ ¦ <input
7 ¦ ¦ ¦ type="text"
8 ¦ ¦ ¦ value={props.children} // here
9 ¦ ¦ ¦ onChange={props.handleNameEdits}
10 ¦ ¦ />
11 ¦ );
12 }
13
14 return <span>{props.children}</span>; // and here
15 };
16
17 GuestName.propTypes = {
18 isEditting: PropTypes.bool.isRequired,
19 handleNameEdits: PropTypes.func.isRequired
20 };
21
22 export default GuestName;
( ps. sorry about the line numbers though, I was using vim)
I'm wondering what does it mean in this case?
I'm so confused right now :(
Steven Parker
231,275 PointsIn vim ":set nonu
" to turn line numbers off (":set nu
" for back on).
oliverchou
20,886 Pointsthanks~ that makes sense, I totally forgot to do that
1 Answer
Steven Parker
231,275 PointsApparently you're not the only one to find this concept challenging. Take a look at this blog article written by someone who also found this confusing but eventually came to understand it.
oliverchou
20,886 PointsI got it. The article is quite helpful, thanks~
oliverchou
20,886 Pointsoliverchou
20,886 PointsMy guess is that it serves as a similar function to the 'super() in OOP classes'. I'm not sure