Y
Hacker News
new
|
ask
|
show
|
jobs
by
bacro
1558 days ago
Waste of memory by creating new function objects on each render.
3 comments
beaconstudios
1558 days ago
Micro-optimisations aren't useful. If you get to the point where the performance cost of inline functions is a bottleneck, you probably shouldn't be using React at all.
link
bacro
1558 days ago
Maybe, but I just prefer to have a named function defined with a useCallback and just call it.
link
beaconstudios
1558 days ago
That's fine, but that's more of a stylistic preference than a performance concern.
link
erikpukinskis
1558 days ago
Won’t V8 just optimize this anyway? I doubt there’s any real difference in memory usage.
link
bacro
1558 days ago
I am not sure, it has a closure for the 'error' local variable.
link
symlinkk
1558 days ago
Yeah probably best to move this to a function outside the render loop with useCallback
link