bezzoon
bezzoon

Reputation: 2019

How to see change in observe with mobx-state-tree

I want to be able to see the new player that was added from mobx observe.

https://codesandbox.io/s/prod-dawn-z5jdv?file=/src/index.js

I am only able to see a lot of metadata. The metadata is difficult to navigate and low level!

I just want to see the new Player object that was added in the observers!

Upvotes: 1

Views: 800

Answers (1)

bezzoon
bezzoon

Reputation: 2019

I just figured it out! The way to do this is to use getSnapshot()

I'm not sure why that is / what the reason for this is under the hood but I know the mobx docs covers getSnapshot!

observe(store.zone.players, (change) => {
  const newPlayer = change.newValue.getSnapshot()
  ...do whatever else you need to do
});

Upvotes: 1

Related Questions