How to reset a deep store?

I have some object within a store. Some filed inside of it has an array of objects. How can I reset the state properly? Here is the demo: https://playground.solidjs.com/anonymous/17bdf18c-3b03-4a27-ab94-2c8a6a3a458d I have notices some weird behavior: add new item, and press reset after. Nor produce, nor reconcile helped me. Am I doing something wrong?
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
4 Replies
Madaxen86
Madaxen864mo ago
e.g.
const handleReset = () => {
//setModel({ ...structuredClone(DEFAULT_MODEL) });
setModel(
produce((prev) => {
prev.children = [];
return prev;
}),
);
};
const handleReset = () => {
//setModel({ ...structuredClone(DEFAULT_MODEL) });
setModel(
produce((prev) => {
prev.children = [];
return prev;
}),
);
};
EricRovell
EricRovellOP4mo ago
So there is no other way just to reset the state in generic way? I have to reset such structures manually?
Madaxen86
Madaxen864mo ago
Solid tracks by reference. So a shallow copy won’t work on the array. So you either have to reset nested objects / array manually because their reference does not change. Or you could make the DEFAULT_MODEL a function which returns the data thus getting a new reference: https://playground.solidjs.com/anonymous/3f7a1bad-6dd7-4d95-a365-a899247922fb
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
EricRovell
EricRovellOP4mo ago
Got it, thank you

Did you find this page helpful?