If there are results and you console.log(isValidEnterSubmit) you might see a number like 12 as the last value in the condition is assigned to the variable. Explicit length checks like searchResults.length > 0 avoid this issue and is therefore preferred.
Code like this can be confusing:
If there are results and you
console.log(isValidEnterSubmit)
you might see a number like12
as the last value in the condition is assigned to the variable. Explicit length checks likesearchResults.length > 0
avoid this issue and is therefore preferred.Also in JSX this is problematic:
This will render
0
if there are no results, as numbers are emitted to the DOM, but booleans are not.Theres a rule for this in an external plugin, but I'd like to avoid adding yet another plugin – at least as long as consumers of this package have to install plugins separately.