Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting incorrect values from redux inside onAction #46

Closed
s-z-s opened this issue Jun 21, 2021 · 2 comments
Closed

getting incorrect values from redux inside onAction #46

s-z-s opened this issue Jun 21, 2021 · 2 comments

Comments

@s-z-s
Copy link

s-z-s commented Jun 21, 2021

I'm trying to logout user after sometime when there is no item in cart (stored in redux) in my kiosk type application.

const handleActivity = (isActive: boolean) => {
      setActive(isActive);
      console.log('active: ' + isActive);
      if (!isActive && cartItems.length==0) {
            logout();
      }
}

But length is returned 0 when the function is called during first inactivity when there is an item in the cart. If the same function is called on a button press, correct value is returned.
What should I do to get correct value everytime?

@jkomyno
Copy link
Owner

jkomyno commented Sep 28, 2021

Hi, at first glance it seems that you're updating the state twice while handling your activity, which may cause odd behaviours.
Try shifting line 2 down like this:

const handleActivity = (isActive: boolean) => {
      console.log('active: ' + isActive);
      if (!isActive && cartItems.length==0) {
            // update the state once such that state.isActive = isActive and a logout is performed
      }
}

@jkomyno
Copy link
Owner

jkomyno commented Nov 8, 2021

Closed for inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants