React-Native Android action error: 'undefined is not an object (evaluating "action.type")

I am using React Native v.43.0-rc.3 and have this error in my Android emulator when I press the toggle button:

undefined is not an object (evaluating 'action.type')

      

My toggle button is wired to function in /action/index.js

:

export const toggleUpdateSwitch = (showUpdates) => {
  // error goes away when i remove this line below ----+v
  AnalyticsTracker.trackEvent({"category": "profile", "action" : "toggle", "label": "section/updates"})

  async dispatch => {
    ToastAndroid.show(TOGGLE_UPDATES_NO_DATA_MESSAGE, ToastAndroid.LONG, ToastAndroid.CENTER);
    const response = await fetch('http://my.url.com/doSomething', { headers, method: 'GET' });
  }
}

      

So I added the line above (AnalyticsTracker) and what is causing the switch error. Any ideas?

Screenshot of emulator error:

emulator error action.type undefined

+3


source to share


1 answer


I had this problem before. You must enter the tracker code inside your asynchronous mailing. In my experience, whenever I have an asynchronous post to my functions, I always get this error if I have synchronous code outside of it. I have no clear idea of ​​why this is happening, but I know I fixed it for me.



My theory is that when you execute an asynchronous process, you start a different thread. With synchronous code outside of it, something happens on the main thread but returns nothing. Hence, you get undefined not an object when you do action.type, because by default I think RN is expecting an object with a type attribute to return, but you are not returning anything.

+1


source







All Articles