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

carlos .
carlos .
9,703 Points

Syntax error. Started getting an error when we started creating multiple components.

I started receiving an error.

app.jsx:39 Uncaught TypeError: Cannot read property 'string' of undefined
    at eval (eval at transform.run (babel-browser.min.js:4), <anonymous>:65:24)
    at Function.transform.run (babel-browser.min.js:4)
    at exec (babel-browser.min.js:4)
    at babel-browser.min.js:4
    at XMLHttpRequest.xhr.onreadystatechange (babel-browser.min.js:4)
function Header(props){
  return (
      <div className="header">
          <h1>{props.title}</h1>
        </div> 
  );
}

Header.propTypes = {
  title: React.PropTypes.string.isRequired,
  };

/*
function Counter(props){
  return(

  );
}
*/
function Player(props){
  return(
      <div className="player">
              <div className="player-name"> 
                  {props.name}
              </div>
                  <div className="player-score">
                      <div className="counter">
                          <button className="counter-action decrement"> - </button>
                           <div className="counter-score"> {props.score} </div>
                          <button className="counter-action increment"> + </button>
                      </div>
              </div>
      </div>
  );
}

Player.propTypes = {
  name: React.propTypes.string.isRequired, 
  score: React.propTypes.number.isRequired,
};

function Application(props) {
  return (
    <div className="scoreboard">
        <Header title={props.title} />
        <Player name="Jime Hoskins" score={31} />
    </div>
  );
}
Application.propTypes = {
  title: React.PropTypes.string,

};
Application.defaultProps = {
  title: "Scoreboard", 
}


ReactDOM.render(<Application />, document.getElementById('container'));

https://jsfiddle.net/debtitor/4dstzpwo/#&togetherjs=0gFxHabka6

embed code: <script async src="//jsfiddle.net/debtitor/4dstzpwo/embed/js,html,css,result/dark/"></script>

2 Answers

Andrew Kiernan
Andrew Kiernan
26,892 Points

Ah, I think I got it. For your Player PropTypes, need to capitalize the "p" in "React.propTypes"

carlos .
carlos .
9,703 Points

Bingo! Andrew, we have a winner. Ok, that's it, I'm buying a bigger monitor..... or two. Squinting at two tiny windows open on this 11" Macbook Air apparently is not productive.

Andrew Kiernan
Andrew Kiernan
26,892 Points

Hi Carlos!

The only thing I'm noticing is there is no closing </div> tag in your Player component for the top-most div (<div className="player">).

Try fixing the closing tag and see if that works.

carlos .
carlos .
9,703 Points

Yeah I caught that too. Phone rang before I could paste the change. Now still getting an error. The above code is updated with the missing closing div tag and the updated error.