JSX && Render Trap Playground

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…

Why it matters

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.

The key idea

&& returns its left side, and React prints numbers

Common mistakes

Try it in this playground