I'm using a third-party library that has a function that takes functions as arguments. I'm doing some conditional checks to decide whether or not to add a particular function as a parameter and in some cases I don't want to provide a function. Providing null in that cases throws an error.
I found this code which works, but I don't fully understand what's happening.
compose(__DEV__ ? devTools() : f => f)
Is f => f
equivalent to () => {}
an empty anonymous function?
f => f
is the identity function. It simply returns the argument that was passed in.
This function is often used as a default values for transformation processes, since it doesn't perform any transformation.
Is
f => f
equivalent to() => {}
an empty anonymous function?
No. The empty function doesn't return anything. The identity function returns the passed in argument.