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 Basics (2018) Understanding State Understanding State Review

I can't figure out what's suppose to go here. I've reviewed the videos a few times. I guess I'm just missing it.

Complete the code so that the isConfirmed state updates its value based on the previous state.

confirmGuest = () => {
  this.setState( prevState => ({ 
    isConfirmed: !___.isConfirmed
  }));
}

2 Answers

Oh, because it's just changing a boolean value to its opposite. I was thinking it wasnted a '!== prevState.isConfirmed" or something like that and it wasn't clicking lol Dumb question.

Ooo. It's just "prevState". But why is there an '!' before it? That's what was throwing me off.

! is the logical NOT operator. In this case, it's basically just a quick way of flipping the boolean value. If the isConfirmed state was true, firing this event handler would change it to false; and if it started as false, the handler would flip it to true. Similar to using if/else if logic, but without explicitly writing it all out, since you just want the boolean to flip to the only other option.