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
The 'else' line of the ternary does nothing. DatePicker.defaultProps.onChange references a function, but the function is not called as the brackets () are missing.
Even if we did add the brackets, DatePicker.defaultProps.onChange is an empty function, so calling it achieves nothing.
The code is therefore equivalent to just onChange && onChange(changedDate, event) which can be more simply written onChange?.(changedDate, event)
Providing an empty function, as opposed to undefined, as the default prop, does not appear useful, as the calling code always checks that the prop is truthy (not undefined) before calling it. We are forced to check the function is not undefined (rather than relying on the default prop always being defined) as the user can pass null as the event handler prop, and we do not want to fail in that case.
With the above code change, we no longer reference the default prop. Also, calling an empty function will never have a different effect than doing nothing at all.
So it would seem reasonable to refactor these 3 lines of code into one in the many places where they appear, and to remove the default prop empty functions as they are not needed.
This refactoring will then make it easier to implement further changes, such has correctly handling the input of date ranges in the textbox, as requested in issues #3596, #3906, #4002.
The text was updated successfully, but these errors were encountered:
Throughout
index.tsx
there are many instances of code similar to the below:This is problematic for several reasons:
DatePicker.defaultProps.onChange
references a function, but the function is not called as the brackets()
are missing.DatePicker.defaultProps.onChange
is an empty function, so calling it achieves nothing.onChange && onChange(changedDate, event)
which can be more simply writtenonChange?.(changedDate, event)
null
as the event handler prop, and we do not want to fail in that case.So it would seem reasonable to refactor these 3 lines of code into one in the many places where they appear, and to remove the default prop empty functions as they are not needed.
This refactoring will then make it easier to implement further changes, such has correctly handling the input of date ranges in the textbox, as requested in issues #3596, #3906, #4002.
The text was updated successfully, but these errors were encountered: