DEV Community

Arian Krasniqi
Arian Krasniqi

Posted on

Do I have to use Arrow Function in Function Components in React

Is it preferable to use Arrow Function in React, while always using Function Components with React Hooks, instead of using Class Components.
Do I have to use Declarable Function Name() { } or Arrow Function () => { }.

Top comments (1)

Collapse
 
ekeijl profile image
Edwin • Edited

There is no preference when using hooks, but they are not the same.

Both function declarations function Name() {} and function expressions const Name = () => {}; are perfectly fine when using React hooks. The main difference is that function declarations are hoisted (moved) to the top of their scope, see here for an explanation.