Boolean value doesn't change

I have a react reducer function and ı tried to change the data with an incoming object. İf id equal change the boolean state value but it does not change.

      return {
        users: => {
          if ( === {
            user.isComplete = !user.isComplete;
          return user;

Are you sure it’s meeting the conditions to change in the first place? And are you getting an error or just no change for that section?

I don’t get an error and I am sure.

One thing you can try is just adding a console.log(, above your if statement and see if those two numbers are ever matching up. Maybe the bug is happening somewhere else

I tried it’s true. :slight_smile:

Hmm weird. So if you console.log(user) before and after your if statement does it look like the boolean is flipping for you?

Some functions change it but this case just change once.
Example: true => false
after it’s stays false

That doesn’t seem right. If you console.log(user) you should hopefully see an object in your logs not a boolean.

A lot of times if you get a situation where you’re trying to flip a boolean and it gets “stuck” on false or true it can mean that you’re updating the value twice but you just don’t realize it. So every time it flips it just flips right back but it’s too fast for you to notice without debugging or adding some console logs

Sorry, ı wrong read. I can see an object.

Okey, well what can ı this case?

Basically you’re looking to see if the object is what you expect it to be at each point in time.

Is it starting with user.isComplete as true when it comes in? Or is it false. Do you expect it to flip? Does it flip when you expect it to?

Are you seeing the reducer fire more than once when you expect it to only fire one time?

You just have to keep asking yourself questions like that and explore what’s actually happening. Once you find something that seems odd you can use that piece of information to figure why it’s doing something you don’t expect.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.