You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many libraries require named functions for various things, but almost all of them end up taking those functions as expressions, rather than requiring them to be declarations. For instance, React's forwardRef works best with a named function rather than an arrow function, because React will use the name for things like debugging information. But that function is an expression passed to forwardRef(); it isn't usually (and never has to be) a function declaration which binds the function to a variable in scope. That's the thing our team actually wants to avoid. We want to always use const to declare variables, never function; and we never want to use anonymous non-arrow function expressions; but we sometimes need to use named function expressions to work well with certain libraries.
Suggested Solution
An option such that this code is correct:
# Arrow function
const doSomething = () => {
console.log('Doing something!');
};
# Named function expression
useThisFunction(function doSomething() {
console.log('Doing something!');
});
while this code is incorrect:
# Named function declaration
function doSomething() {
console.log('Doing something!');
}
# Anonymous (non-arrow) function expression
useThisFunction(doSomething() {
console.log('Doing something!');
});
Perhaps allowNamedFunctions: "only-expressions"?
Help Needed
I may be able to work on this if it would be accepted.
The text was updated successfully, but these errors were encountered:
Description
Many libraries require named functions for various things, but almost all of them end up taking those functions as expressions, rather than requiring them to be declarations. For instance, React's
forwardRef
works best with a named function rather than an arrow function, because React will use the name for things like debugging information. But that function is an expression passed toforwardRef()
; it isn't usually (and never has to be) a function declaration which binds the function to a variable in scope. That's the thing our team actually wants to avoid. We want to always useconst
to declare variables, neverfunction
; and we never want to use anonymous non-arrow function expressions; but we sometimes need to use named function expressions to work well with certain libraries.Suggested Solution
An option such that this code is correct:
while this code is incorrect:
Perhaps
allowNamedFunctions: "only-expressions"
?Help Needed
I may be able to work on this if it would be accepted.
The text was updated successfully, but these errors were encountered: