Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
bacro
· 4y ago · 0 comments
Waste of memory by creating new function objects on each render.
Comments
[–]
beaconstudios
4y 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.
[–]
bacro
OP
4y ago
Maybe, but I just prefer to have a named function defined with a useCallback and just call it.
[–]
beaconstudios
4y ago
That's fine, but that's more of a stylistic preference than a performance concern.
[–]
erikpukinskis
4y ago
Won’t V8 just optimize this anyway? I doubt there’s any real difference in memory usage.
[–]
bacro
OP
4y ago
I am not sure, it has a closure for the 'error' local variable.
[–]
symlinkk
4y ago
Yeah probably best to move this to a function outside the render loop with useCallback