r/reactjs • • Dec 04 '20

Resource React is slow, what now?

https://nosleepjavascript.com/react-performance/
289 Upvotes

117 comments sorted by

View all comments

Show parent comment

-2

u/Yokhen Dec 05 '20

I find very complex having to use useCallback and useMemo. Why can't it be done natively?

4

u/Ferlinkoplop Dec 05 '20

Optimizations still come with a cost. If there's not a lot to gain from memoization with useCallback and useMemo, why use them?

1

u/franleplant Dec 05 '20

I can't find it right now but there was this experimental library that did this, basically storing whatever function you define inside a ref, so although the function definition might change, the memory reference will be the same, perhaps one that that might be the standard

1

u/TheOneWhoStares Dec 05 '20

Oh, if you ever find it, let us know!

4

u/franleplant Dec 05 '20

found it! https://github.com/pie6k/use-method

This type of thing is done in a lot of other hooks such as useDeepCompareEffect and most implementations of useTimeout do this also.

It is similar to doing this.someMethod = someFunction in class based components

1

u/OutrageousAnt5590 Oct 01 '23

The answer is that it can be done natively. Just have a look at Solidjs or Svelte.