Link to home
Start Free TrialLog in
Avatar of tom1234
tom1234Flag for Korea, Republic of

asked on

In mobx-state-tree, what is the difference, 'getSnapshot' and 'toJSON'.

I'm using mobx-state-tree
What I want to know is  what the difference is 'getSnapshot' and 'toJSON'.
I think both of them are doing same role that returns json format data.
ex)
between
var jsonData = getSnapshot(chatsStore.userInfo)
  and
var jsonData = chatsStore.userInfo.toJSON();
       
What's difference??
Avatar of ste5an
ste5an
Flag of Germany image

What I want to know is  what the difference is 'getSnapshot' and 'toJSON'.
 I think both of them are doing same role that returns json format data..
No. According to the specs getSnapshot returns an object (no quotes around the field names).

<!DOCTYPE html>
<html>
<body>
	<script>
		var obj = {};
		obj.test = 'TEST';
		console.log(obj);
		console.log(JSON.stringify(obj));
	</script>
</body>
</html>

Open in new window

User generated image
For the rest, the actual value be identical.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.