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 Toggling Edit State for Guests

TypeError: _this.state is not a function ?


24 | ] 25 | } 26 |

27 | toggleGuestPropertyAt = (property, indexToChange) => 28 | this.state({ 29 | guests: this.state.guests.map((guest, index) => { 30 | if (index === indexToChange) {

toggleGuestPropertyAt = (property, indexToChange) => this.state({ guests: this.state.guests.map((guest, index) => { if (index === indexToChange) { return { ...guest, [property]: !guest[property] }; } return guest; }) });

toggleConfirmationAt = index => this.toggleGuestPropertyAt("isConfirmed", index);

handleConfirmation={() => props.toggleConfirmationAt(index)}

I got this error when when changing my function to use property. This happens when clicking checkbox also when clicking editing button just the different function toggleEditingAt When I searched on the internet for this error it gave me answers about how to bind this. Which I am not sure about, what do you think guys?

Jason Welsh
.a{fill-rule:evenodd;}techdegree seal-36
Jason Welsh
Treehouse Project Reviewer

Hi, so state is not a function, but rather an object we use to hold the current state of a component. setState() is a function we use to change the state of the state object. It takes two arguments - the first is an object that we will merge with state, and the second is a callback that is basically never used.

So in this case you have this.state instead of this.setState. You need to update the state object with the setState function.

Hope that helps :)