Hello fellow developers out there,
I have this question which my colleagues don't seem to reach an agreement about.
Considering JS hoisting and that functions expressions are not called when the component mounts, it seems to be safe to assume we are not going to have any problems by declaring methods violating "used before it was defined".
But I wonder if is it safe to ignore lint's warnings about it and declare component's functions alphabetically or according to logic blocks or whatever...? Even though if a function declared first calls another one declared later?
For example (this is just a simplification of a large functional component with lots of functions where it would be really hard for another developer to get organized around all of it):
const SomeRandomFC = () => {
// User logics
const changeUser = id => {
if (id !=== currentId) {
getDatabase(id);
}
const getUser = id => ...
// Database logics
const getDatabase = user => [fetch logics];
const updateDatabase = id => ...
}
Thanks!