lxsmnsyc / forgetti

Solve your hook spaghetti (with more spaghetti). Inspired by React Forget.
https://forgetti.vercel.app/
MIT License
352 stars 7 forks source link

0.6.0 #23

Closed lxsmnsyc closed 1 year ago

lxsmnsyc commented 1 year ago
SukkaW commented 1 year ago
  • React frees up useMemo references in a scheduled way (think of LRU). useRef doesn't have this kind of behavior

IMHO forgetti should keep using useMemo to optimize the memory usage (which is really important as we are caching basically everything), while skipping the useRef transformation to keep the behavior correct.

lxsmnsyc commented 1 year ago

IMHO forgetti should keep using useMemo to optimize the memory usage (which is really important as we are caching basically everything), while skipping the useRef transformation to keep the behavior correct.

No I can't do that, because if it was temporary then that impacts the use of ref transformations. It has to be persistent at all times.

SukkaW commented 1 year ago

No I can't do that, because if it was temporary then that impacts the use of ref transformations. It has to be persistent at all times.

What I means that, why not leave useRef usages alone and do not transform useRef at all. This will keep the behavior correct, while the rest of the caches can benefit from useMemo's auto gc. Since we are cacheing almost everything, it is important to optimize the memory consumption.

lxsmnsyc commented 1 year ago

Since we are cacheing almost everything, it is important to optimize the memory consumption.

Exactly. The compiled version of useRef is actually cheaper than the one's in React. I can't revert this behavior anymore because useRef is no longer bounded by hook rules

SukkaW commented 1 year ago

@lxsmnsyc Can you release an alpha version of 0.6.0 (e.g. 0.6.0-alpha.1) so I can try this out in some of my hobby projects, and discover some edge cases?

lxsmnsyc commented 1 year ago

@lxsmnsyc Can you release an alpha version of 0.6.0 (e.g. 0.6.0-alpha.1) so I can try this out in some of my hobby projects, and discover some edge cases?

Released 0.6.0-alpha.0

SukkaW commented 1 year ago

Released 0.6.0-alpha.0

Just found an issue, opened https://github.com/lxsmnsyc/forgetti/issues/25.