The early days of the online felt just like the wild west when it got here to coding practices — simply make it work. Then we turned enlightened to raised practices, separating HTML from CSS and JavaScript. Then got here React and JSX, the place we mix JavaScript, HTML, and even CSS with Styled Parts — what a sublime mess we have made!
Each from time to time a part of that mess is me seeing 0
displaying within the output of my JSX code, and I am reminded why: improper dealing with of variable typing, mixed with utilizing &&
. Let me clarify!
One of many widespread patterns in JSX is:
<div>Some header</div> {someValue && <div>Some header</div>}
The sample is sensible however take a look at the distinction in outputs between string and quantity varieties:
"0" && "Factor" > "Factor" 0 && "Factor" > 0
Observe {that a} string worth of 0
permits the second worth to be returned, however a quantity typed 0
merely returns the 0
. The perfect apply is at all times to forged the worth to a Boolean
in your JSX:
{Boolean(worth) && ....}
Typescript and even PropTypes
may also help to catch these points however even seasoned veterans generally hit these ache factors.
LightFace: Fb Lightbox for MooTools
One of many internet elements I’ve at all times cherished has been Fb’s modal dialog. This “lightbox” is not like others: no darkish overlay, no obnoxious animating to measurement, and it would not attempt to do “an excessive amount of.” With Fb’s dialog in thoughts, I’ve created LightFace: a Fb lightbox…
Ideas for Beginning with Bitcoin and Cryptocurrencies
One of the rewarding experiences of my life, each financially and logically, has been shopping for and managing cryptocurrencies like Bitcoin, Litecoin, Ethereum. Like studying every other new tech, I made rookie errors alongside the way in which, however realized some greatest practices alongside the way in which. Try…
MooTools ContextMenu Plugin
ContextMenu is a extremely customizable, compact context menu script written with CSS, XHTML, and the MooTools JavaScript framework. ContextMenu lets you provide trendy, useful context menus in your web site. The XHTML Menu Use a listing of menu gadgets with one hyperlink per merchandise. The…
Create a Dynamic Desk of Contents Utilizing MooTools 1.2
You’ve got most likely observed that I draw back from writing actually lengthy articles. Listed here are a number of explanation why: Most web site guests are coming from Google and simply need a straight to the purpose, bail-me-out ASAP reply to a query. I’ve observed that I’ve a tough time…
Source link