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

TypeError: _this.state is not a function ?

App._this.toggleGuestPropertyAt

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
seal-mask
.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 :)