Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React by Example Building the Application Building the GuestList Component

Timothy Grindall
Timothy Grindall
7,843 Points

TypeError: Cannot read property 'map' of undefined

So I followed the videos and checked and rechecked my code for errors but I can find none. When you click on the checkbox I get an error saying "TypeError: Cannot read property 'map' of undefined". The error is in App.js on line 26 which says "guests: this.state.quests.map((guest, index) => {". I've included the relevant files below for examination:


import React, { Component } from 'react';
import './App.css';
import GuestList from './GuestList';

class App extends Component {

  state = {
    guests: [
        name: 'Treasure',
        isConfirmed: false,
        name: 'Nic',
        isConfirmed: true,
        name: 'Matt K',
        isConfirmed: false,

  toggleConfirmationAt = indexToChange =>
      guests: this.state.quests.map((guest, index) => {
        if (index === indexToChange) {
          return {
            isConfirmed: !guest.isConfirmed
        return guest;

  getTotalInvited = () => this.state.guests.length;
  // get AttendingGuests = () =>
  // getUnconfirmedGuests = () =>

  render() {
    return (
    <div className="App">
        <p>A Treehouse App</p>
            <input type="text" value="Safia" placeholder="Invite Someone" />
            <button type="submit" name="submit" value="submit">Submit</button>
      <div className="main">
            <input type="checkbox" /> Hide those who haven't responded
        <table className="counter">



export default App;


import React from 'react';
import PropTypes from 'prop-types';

import Guest from './Guest';

const GuestList = props => 
        {props.guests.map((guest, index) =>
                handleConfirmation={() => props.toggleConfirmationAt(index)} />

GuestList.propTypes = {
    guests: PropTypes.array.isRequired,
    toggleConfirmationAt: PropTypes.func.isRequired

export default GuestList;


import React from 'react';
import PropTypes from 'prop-types';

const Guest = props => 
                onChange={props.handleConfirmation} /> Confirmed

Guest.propTypes = {
    name: PropTypes.string.isRequired,
    isConfirmed: PropTypes.bool.isRequired, 
    handleConfirmation: PropTypes.func.isRequired

export default Guest;

It renders fine before you click on the checkbox.

3 Answers

Timothy Grindall
Timothy Grindall
7,843 Points

I found the answer: it's a typo. "quests" is supposed to be "guests" so when I changed that it worked.


first of all you need to import App to the file with the map function.

Cannot read property 'map' of undefined" generally means the javascript interpreter is trying to map over some data but the data isn't there. Try to figure out whats going on in the quests array