Re:Why I'm not a React Native developer
by Rockslide on Saturday August 19, 2017 @03:41PM
(#15055176)
It certainly doesn't hurt to "cast" the input to boolean. But your second example is the next code smell, because it should just be
(which still works as expected even when dealing with null or undefined).
[ Parent
| on HN ]
Agreed, but you can't anticipate what another dev could write :)
Or if you pass down that `isConnected` down to a library where for some reason they assumed `null` should default to `true`
Of course it's very unlikely, but my point is you can't know all use cases of `this.state.isConnected` in advance on a large project so as you say it doesn't hurt to sanitize the input.