1
votes

I would like to use Mobx in React project (with Meteor) and create global Notification store with mobx-react.

I try to init the module, but I don't know why it returns an empty object :

import { observable } from 'mobx';

class NotificationStore {
  @observable notifications = ['test', 'new notification'];
}

var store = window.store = new NotificationStore;

export default store;

And in my App.js :

import store from '../../components/NotificationStore';

console.log(store); // return Object { }

Anyone knows why my object is empty ?

Thank you community !

1
That's very odd. It works for me. Maybe you overwrite window.store somewhere else in your code? - Tholle
Hi ! In your example, the object in empty too, nop ? - s-leg3ndz
Write store.notifications.toJS() and you will see the values. - Tholle
Haw yes, it work with store.notifications.toJS(), thank you :) Maybe the problem is because it's on MeteorJS env .. thank you for your help ! - s-leg3ndz

1 Answers

1
votes

I think it is working as intended. Try to write store.notifications.toJS() in this console to see your array. Keep in mind that a MobX-array is not a real JavaScript array, so you might have to use toJS when logging or passing values to external libraries for it to work properly.