Why doesn't the store update trigger a re-render of all dependent elements? #674
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You are destructuring your store in the rest parameters of your component. This loses reactivity. In general don't destructure props with Solid. In your case only line 11 in Board.tsx is an issue. But if your columns were more dynamic they'd have a problem too. Also Solid Stores allow for more performant path based setters (similar to ImmutableJS).. cloning in setStore top-level causes everything to have to re-evaluate throughout the whole object. Where using the path gives us the ability to perform the most localized change without diffing. Here is how I used setStore(
"columnItems",
(column) => column.id === columnId,
"items",
(prevItems) => shuffleArray(prevItems)
);
// previously:
setStore((prevBoard) => ({
columnItems: prevBoard.columnItems.map((column) =>
column.id === columnId
? { ...column, items: shuffleArray(column.items) }
: column
),
})); Instead of cloning it runs through the path and only shuffles the arrays that match the filter at the end. In fact once I made this change I needed to remove the destructuring on Column.tsx. See working version here: https://playground.solidjs.com/?hash=101083038&version=1.1.1 |
Beta Was this translation helpful? Give feedback.
You are destructuring your store in the rest parameters of your component. This loses reactivity. In general don't destructure props with Solid. In your case only line 11 in Board.tsx is an issue. But if your columns were more dynamic they'd have a problem too.
Also Solid Stores allow for more performant path based setters (similar to ImmutableJS).. cloning in setStore top-level causes everything to have to re-evaluate throughout the whole object. Where using the path gives us the ability to perform the most localized change without diffing. Here is how I used
setStore
: