DEV Community

loading...

Discussion on: Status instead of isLoading boolean?

sleeplessbyte profile image
Derk-Jan Karrenbeld

!!value is effectively the same as Boolean(value) and will therefore always return false in the case of all falsy values.

!!value && <MyComponent />
Enter fullscreen mode Exit fullscreen mode

Will always resolve to false if the left hand side is falsy. False values are not rendered, so yes, that would catch all falsey values.

I still recommend Boolean(value) && <MyComponent /> over !!value && <MyComponent /> because it is both explicit and easier to read, albeit it a bit longer. It's easy to skip over !!, but more importantly, it's easy to forget to add !!. If you're used to seeing Boolean(...), that's less likely.

Thread Thread
larsejaas profile image
LarsEjaas

That's actually a great point! I haven't used Boolean(..) in my code I think 🤔 But I like how it's more descriptive! Thanks for taking the time to responde 😊👍

Thread Thread
sleeplessbyte profile image
Derk-Jan Karrenbeld

The _callable Global Objects are a gem ✨.

I also recommend Number(value) over the obscure +value, which both are usually better to "type-cast" than parseInt or parseFloat, as it will properly fail when the value isn't representing a number, instead of doing something unexpected.

Thread Thread
larsejaas profile image
LarsEjaas

Ahh, cool. I haven't digged super deeply into the differences, I just really like "Number" because "it does what it says on the tin" 😆 I really like easy readable code 😊

Forem Open with the Forem app