Refresh data on external event


#1

Hi to all,
I have a page component with a list of conversations.
In app.js I have an event handler for received notification via onesignal.
How can I update page data from the event handler?
Is setState accessible from external? How? If so, is it a bad practice?
Thanks


#2

ok, maybe solved:

  1. I’ve added app.emit inside the received notification handler
  2. I’ve added app.on inside the page component initPage. In the app.on i’ve queried db and called setState
    P.S. Little problem: app.on is called two times

#3

Make sure you also call app.off in this component’s pageBeforeRemove to avoid attaching handler multiple times


#4

Thanks very much Vladimir!