Question about the guarantees of useMemo
#3027
-
Hi Folks! I had a somewhat-quick question about some of the guarantees preact makes about the Does this section from the react documentation, still hold true in preact?
-- Why do I ask? Suppose we have a function that creates a closure over some instantiated variable:
We want to use this inside of a component. However, each instance of that component should have distinct instances of
Based on the react documentation, this would be considered |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's a guarantee we can bring, we'd have to look at a few of the current things we're doing in Suspense but generally we're not planning to support something as the likes of concurrent mode. React implements an idea of lanes, a lane can be used to perform work in, this means that if you memoize something in lane 1 but this isn't used that it will have a different reference in a potential other lane. As we are not implementing this assumption voids when porting it to Preact, do note that there could currently be an issue with Suspense when it comes to this exact case 😅 currently we are erasing all hooks state both on initial and subsequent suspense, this is something React doesn't do I think, they do re-run the memo func iirc. |
Beta Was this translation helpful? Give feedback.
It's a guarantee we can bring, we'd have to look at a few of the current things we're doing in Suspense but generally we're not planning to support something as the likes of concurrent mode.
React implements an idea of lanes, a lane can be used to perform work in, this means that if you memoize something in lane 1 but this isn't used that it will have a different reference in a potential other lane. As we are not implementing this assumption voids when porting it to Preact, do note that there could currently be an issue with Suspense when it comes to this exact case 😅 currently we are erasing all hooks state both on initial and subsequent suspense, this is something React doesn't do I thi…