S
SolidJS•2y ago
PureSoul

setStore function replace object value

https://playground.solidjs.com/anonymous/f0b1602b-24a8-48db-a37d-e60db6eb3f85
function Counter() {
const [store, setStore] = createStore({
a: { b: { c: 2, d: 3 }, e: { f: { g: 4, h: 5 } } },
});
setStore({ a: { b: { e: 4 } } });
console.log(JSON.stringify(store));

return <div>Test</div>;
}
function Counter() {
const [store, setStore] = createStore({
a: { b: { c: 2, d: 3 }, e: { f: { g: 4, h: 5 } } },
});
setStore({ a: { b: { e: 4 } } });
console.log(JSON.stringify(store));

return <div>Test</div>;
}
In this example setStore is replacing whole store, instead it should merge the store.
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
7 Replies
foolswisdom
foolswisdom•2y ago
I think this is expected behavior. I think solid only merges the top level of the object you pass to set store, it doesn't merge recursively setStore("a", "b", {e: 4}) will merge, I think
PureSoul
PureSoulOP•2y ago
why it remove the e key from top level store?
foolswisdom
foolswisdom•2y ago
Oh, I see, it seems to be removing the "e" key from the top level 🤔. I don't think that's meant to be the behavior?
Otonashi
Otonashi•2y ago
e isn't top level though? it's part of a the merging behaviour is shallow
foolswisdom
foolswisdom•2y ago
Ah you're right. All the nesting confused me (and I was falling asleep 🙂)
PureSoul
PureSoulOP•2y ago
Is it a bug?
foolswisdom
foolswisdom•2y ago
No As explained here
Want results from more Discord servers?
Add your server