ReactJS defaultProps empty function declaration
I don't think there is a right answer for this.
If you want to be more explicit in your code, go with the null
and check if the function is null
before calling it.
If you want to have less code, go with empty function.
The more important thing I would say, is to be consistent in the entire project.
Important thing to keep in mind is that an empty function ()=>{}
is an object hence its truthy whereas null
and undefined
are falsy.
So if you want to check whether that event handler prop is passed on implementation and handle both cases (supplied and not supplied) differently, it makes more sense to go with null
or undefined
.