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 trial

JavaScript React by Example Building the Application Changing Guest Name in State

oliverchou
oliverchou
20,886 Points

What 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 :(

oliverchou
oliverchou
20,886 Points

My guess is that it serves as a similar function to the 'super() in OOP classes'. I'm not sure

Steven Parker
Steven Parker
229,005 Points

In vim :point_right: ":set nonu" to turn line numbers off (":set nu" for back on).

oliverchou
oliverchou
20,886 Points

thanks~ that makes sense, I totally forgot to do that

1 Answer

Steven Parker
Steven Parker
229,005 Points

Apparently 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
oliverchou
20,886 Points

I got it. The article is quite helpful, thanks~