Guess what {count && <X/>} prints when count is 0, and what is left of X’s state when {tampil && <X/>} turns false. On the neighbourhood head’s screen, real…
Conditions in JSX are in every component: an empty list, a zero count, a panel that opens and closes. Two classic bugs come from here: a number that leaks onto the screen, and state that is lost because the component was unmounted when you only wanted to hide it.
&& returns its left side, and React prints numbers
{items.length && <List />} A length of 0 renders "0". Use {items.length > 0 && …} or a ternary {items.length ? <List /> : null}.&& in JSX 0 and NaN are falsy, but React prints them. Turn them into a boolean first: x > 0, Boolean(x), !!x.false and 0 are both invisible React renders nothing for false, null, undefined and true, but prints numbers and non-empty strings. Different fates.{tampil && <C />} unmounts it, and its state is thrown away. If it must be remembered: hide it with hidden or CSS, return null inside the component, or keep the state in the parent..length &&, then read them all out The list empties, and a 0 shows under the title: a real text node in the DOM.> 0 or a ternary, read them out again A boolean condition or a ternary: no number leaks.tampil && <Kancil />: down and back Kancil is unmounted and mounted anew: his claps start from 0.hidden={!tampil}: down and back Kancil stays mounted, his button only hidden: his claps stay.