Reputation: 14071
I have a fetch in my componentDidMount
that does not refresh the appState
data when I do @observer @inject('appState')
but it would consistently work when I have @inject('appState') @observer
.
At the same time, I'm getting a warning in the console that my order is wrong.
Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'
Which is the correct order and why?
Upvotes: 3
Views: 1645
Reputation: 4978
Decorators are sugar for function calls, so @a @b class C
is a similar to a(b(class C))
, in other words, the inner most (or right most) is the first applied decorator. So applying observer
before applying inject
means: inject("stores")(observer(Component))
, in other words, the order that works for you is the order that is intended: @inject('appState') @oberver Component
Upvotes: 6