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 Connecting the Confirm Guests Handler

Jonas Wu
Jonas Wu
13,928 Points

props.toggleConfirmationAt is not a function?

Hello all,

I think that I follow all the steps in this video. But after clicking the checkbox. I will get this type error.

How would you recommend to fix this issue? Thank you! :)

in the app.js:

app.js
toggleConfirmationAT = (indexToChange) =>
    this.setState({
      guests: this.state.guests.map((guest, index) => {
        if (index === indexToChange) {
          return {
            ...guest,
            isConfirmed: !guest.isConfirmed
          };
        }
        return guest;
      })
    });

<GuestsList
            guests={this.state.guests}
            toggleConfirmationAT={this.toggleConfirmationAT}
          />

in the GuestList.js:

GuestList.js
const GuestList = (props) => {
  return (
    <ul>
      {props.guests.map((guest, index) => (
        <Guest
          key={index}
          name={guest.name}
          isConfirmed={guest.isConfirmed}
          handleConfirmation={() => props.toggleConfirmationAt(index)}
        />
      ))}
    </ul>
  );
};

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

in Guest.js:

Guest.js
const Guest = (props) => {
  return (
    <li>
      <span>{props.name}</span>
      <label>
        <input
          type="checkbox"
          checked={props.isConfirmed}
          onChange={props.handleConfirmation}
        />
        Confirmed
      </label>
      <button>edit</button>
      <button>remove</button>
    </li>
  );
};

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

2 Answers

Michael Hulet
Michael Hulet
47,913 Points

I haven't run this to check, but it seems like you'd get an error like this because you're looking for a function named toggleConfirmationAt, but you've previously named it toggleConfirmationAT (notice the capital "T" instead of the lowercase). JavaScript is case-sensitive, which means toggleConfirmationAt is totally different from toggleConfirmationAT. If you make all your Ts lowercase, I think you might have better results 🙂

Jonas Wu
Jonas Wu
13,928 Points

Thank you Michael :)

It works now, I'll be more careful of the cases next time!