高级前端
react
【Q614】immer 的原理是什么,为什么它的性能更高

immer 的原理是什么,为什么它的性能更高

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 632 (opens in a new tab)

Author 回答者: shfshanyue (opens in a new tab)

const state = {
  user: { id: 3 },
  role: { name: "admin" },
};
 
const proxyState = new Proxy(state, {
  get(target, prop) {
    return target[prop];
  },
});
//=> True
state !== proxyState;
 
//=> True
state.user === proxyState.user;