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

TypeError: props.toggleConfirmationAt is not a function

Hello, I see others have posted about this same problem. I tried going through their solutions but no luck. I don't know what I did wrong. My app works until I check the checkbox, then I get this syntax error: TypeError: props.toggleConfirmationAt is not a function. Can anyone help? Thanks!

In App.js

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

In GuestList.js:

import React from 'react';
import PropTypes from 'prop-types';
import Guest from './Guest';

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
};

export default GuestList;

In Guest.js:

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

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
};

export default Guest;

1 Answer

Ok I solved my own problem here...of course it was a typo!!!

Down in App.js, here was my problem. I fixed it and it works now :)

<GuestList
           guests={this.state.guests} 
             toggleConfirmationAt={this.toggleCoirmationAt}
           />
        </div>
      </div>