0

I'm creating a React Native app and I want to add observable/observer pattern but the observer's render function is not re-executing when the observable changes.

Here is the store where the observable is:

https://github.com/ksairi/GalaApp/blob/development/app/stores/NotificationsStore.js

This is the stores' index file:

https://github.com/ksairi/GalaApp/blob/development/app/stores/index.js

This is the screen where the observer is and this specific line in the render function is the one that should make the render to re-execute again but is not happening.

https://github.com/ksairi/GalaApp/blob/development/app/screens/Notifications.js#L86

Any ideas?

ksairi
  • 11
  • 1
  • 4
  • Not sure if this is the problem, but [here](https://github.com/ksairi/GalaApp/blob/development/app/stores/index.js#L6) it looks like you meant `notificationsStore: new NotificationsStore()`? – kingdaro Feb 25 '18 at 23:32
  • Also, I'd recommend against using static properties in classes. Instead, use normal class properties, reference `this` in the class body, and make instances of them, as shown in the MobX docs https://mobx.js.org/best/store.html#stores – kingdaro Feb 25 '18 at 23:33
  • Thank you for your answer, I tried with class properties and didn't work either. I'm reading about redux now, so I think I will solve this redux instead mobx – ksairi Feb 26 '18 at 01:13
  • If you want to create singleton store, there is how to do it: https://stackoverflow.com/questions/30174078/how-to-define-singleton-in-typescript#answer-36978360 – FisNaN Feb 26 '18 at 02:18

0 Answers0