You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been seeing a common pattern of creating an object that is an instance of a class in a useRef call:
constmapRef=useRef(newMap());
Can we maybe come up with a version of useRef that works a bit similarly to useMemo, but that it only executes the function the first time?:
constmapRef=useCreationRef(()=>newMap());
Looking at this comparatively on jsperf, it seems quite clear that the second version would always be faster when it involves creation of class objects. Especially when considering custom class objects, which could have constructors that do a lot more than just initialization.
If it's welcome, I'm happy to put up a PR for this.
The text was updated successfully, but these errors were encountered:
I've been seeing a common pattern of creating an object that is an instance of a class in a
useRef
call:Can we maybe come up with a version of
useRef
that works a bit similarly touseMemo
, but that it only executes the function the first time?:Looking at this comparatively on jsperf, it seems quite clear that the second version would always be faster when it involves creation of class objects. Especially when considering custom class objects, which could have constructors that do a lot more than just initialization.
If it's welcome, I'm happy to put up a PR for this.
The text was updated successfully, but these errors were encountered: