Skip to content

Object.assign against stores - proxy(obj) vs obj. Why do both work? #1002

Answered by dai-shi
piscopancer asked this question in Q&A
Discussion options

You must be logged in to vote

By work I mean that Valtio continues to track values, meaning it is working

Object.assign(scheduleStore, defaultStore) // ✔ (i used to think it would not work tbh)
Object.assign(scheduleStore, proxy(defaultStore)) // ✔

Yes, when assigning, we make proxies. The simpler one is this:

const obj = {}
const state = proxy({});
state.obj = obj; // this and
state.obj = proxy(obj); // this are the same thing.

We don't recommend this pattern, though, since Valtio v2. (Check the migration note.)

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@piscopancer
Comment options

Answer selected by piscopancer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants