0

I've one method called onChange and it's working as expected on localhost but not on production. Checkout the code below for better understanding:

onChange() {
   const someValue = this.props.dispatch(divideTenByFive()) // returns 2 on both local and prod
   console.log(someValue) // prints 2 on localhost and undefined on production
   console.log(this.props.dispatch(divideTenByFive())) // prints 2 on localhost and undefined on production
   return someValue; 
}

Is it related to Synchronous/Asynchronous programming? How to fix this for production?

Note: I can't share the actual business logic so I've written divideTenByFive() for better understanding. However, I've tried to provide max details but if you're looking for more info please comment below.

Update: I'm not using any middleware

Abhinav
  • 246
  • 2
  • 13
  • are you using some middleware to return the value – Shubham Khatri Nov 14 '18 at 13:17
  • @ShubhamKhatri No, I'm not using any middleware to return the value. It's simple try catch and if else going on inside divideTenByFive() which returns the expected value in production also. – Abhinav Nov 14 '18 at 14:12
  • Need a fully working code rather than 3 lines of code if you need help. Preferably on any open source website like GitHub. – SamwellTarly Nov 14 '18 at 17:38

1 Answers1

0

Can you please try using var instead of const to declare the variable.

Once you’ve set it (to 2 on dev and to “undefined” in production) it cannot be changed.

This is because the value is not yet available, but const will prevent any modification later on.

estinamir
  • 435
  • 5
  • 11