-
Solid docs say:
Which makes sense. (Except for the "similar behaviour"... isn't it the exact same behaviour, assuming your function doesn't have side-effects?) Coming from the React world, the advice is:
Now I'm wondering: does Solid's And if so, what's a good rule of thumb? Like if you have an array of 100 items and you filter on it and then access that five times... should you memoize the filter or not? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
In react, you would use memos not to compute results with the same parameters twice, this is a non-issue in solid anyways, because signals already have an equality check, so they wouldn't trigger computations if updated with the same value. If only for that, you can use plain functions. The same also applies to solid if a value from a complex computation is used multiple times. However, it is even more useful if you have signals with frequent changes but only need to call the subscribers on certain changes, because then you can use As |
Beta Was this translation helpful? Give feedback.
In react, you would use memos not to compute results with the same parameters twice, this is a non-issue in solid anyways, because signals already have an equality check, so they wouldn't trigger computations if updated with the same value. If only for that, you can use plain functions.
The same also applies to solid if a value from a complex computation is used multiple times. However, it is even more useful if you have signals with frequent changes but only need to call the subscribers on certain changes, because then you can use
createMemo
as a reactivity filter to improve performance pretty effectively. For example if you have a volume meter for an audio signal, but only show 4 bars t…