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

Janani Sudershan
Janani Sudershan
1,597 Points

Uncaught TypeError: Cannot read property 'map' of undefined

I am not sure if its is Babel related error as I am new to it. Warning: Failed propType: Required prop players was not specified in Application. Uncaught TypeError: Cannot read property 'map' of undefined at Application (eval at transform.run (babel-browser.min.js:4), <anonymous>:59:20) at ReactCompositeComponentWrapper._constructComponentWithoutOwner (react.js:5720) at ReactCompositeComponentWrapper._constructComponent (react.js:5706) at ReactCompositeComponentWrapper.mountComponent (react.js:5629) at ReactCompositeComponentWrapper.wrapper [as mountComponent] (react.js:12513) at Object.mountComponent (react.js:13175) at ReactCompositeComponentWrapper.performInitialMount (react.js:5767) at ReactCompositeComponentWrapper.mountComponent (react.js:5692) at ReactCompositeComponentWrapper.wrapper [as mountComponent] (react.js:12513) at Object.mountComponent (react.js:13175)

Here is code: var PLAYERS =[ { name: "Theodare", score: 32, }, { name: "Alvin", score: 35, }, { name: "Lily", score: 38, } ];

function Header(props){ return ( <div className = "header"> <h1>{props.title}</h1> </div> ); } Header.propTypes = { title: React.PropTypes.string.isRequired, };

function Player(props){ return ( <div className ="player"> <div className ="player-name"> {props.name} </div> <div className ="player-score"> {props.score} </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} /> <div className="players"> {props.players.map(function(player) { return <Player name={player.name} score={player.score} /> })}

</div> </div> ); } Application.propTypes = { title: React.PropTypes.string, players: React.PropTypes.arrayOf(React.PropTypes.shape({ name: React.PropTypes.string.isRequired, score: React.PropTypes.number.isRequired, })).isRequired, }; Application.defaultProps = { title: "scoreboard", };

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

2 Answers

Amin Ruhul
PLUS
Amin Ruhul
Courses Plus Student 4,762 Points

Because you did not pass players in your Application.

ReactDOM.render(<Application players= { PLAYERS } />, document.getElementById('container'));

Gabriel Florin
Gabriel Florin
2,984 Points

Why I have this error? I did exactly how the teacher did but I have this error. Why? Uncaught TypeError: Cannot read property 'shape' of undefined at eval (eval at transform.run (babel-browser.min.js:4), <anonymous>:99:52) 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)