arrow function vs traditional function definiitions
Answered
GetPsyched posted this in #help-forum
I think I read a discussion about this in #discussions with both implementations being different in minor ways. I defaulted to the traditional
Recently ran ESLint on the code and it gives me warnings to change everything to arrow functions and now I'm doubtful again. Can someone list out the exact differences so that I can pick one once and for all?
function foo() {} for page.tsx et al and const foo = () => {} for any "components" that assist pages.Recently ran ESLint on the code and it gives me warnings to change everything to arrow functions and now I'm doubtful again. Can someone list out the exact differences so that I can pick one once and for all?
Answered by Eric Burel
this kind of syntactic stuff sometimes have an effect at very huge scale, like having an algorithm that runs the function a billion times, you may want to take a look at the perf impact
7 Replies
?
technical differences are limited, also the bundler might alter that anyway so you can't surely tell what ends up in the users browser
I now use function for top level stuff because it's easier to read
this kind of syntactic stuff sometimes have an effect at very huge scale, like having an algorithm that runs the function a billion times, you may want to take a look at the perf impact
Answer
but otherwise do as you prefer
yeah that's fair
My approach is function for top level and arrow for smaller components