WeSearch

Conditional Rendering over Nil Coalescing

Eli Perkins· ·2 min read · 0 reactions · 0 comments · 15 views
#programming#ui#development
Conditional Rendering over Nil Coalescing
⚡ TL;DR · AI summary

The article emphasizes the importance of avoiding nil coalescing in UI code. Instead of using fallback values, developers should implement conditional rendering to handle nil values appropriately. This approach enhances user experience by providing clear indicators for loading states, errors, or empty content.

Key facts
Original article
Blog - Eli Perkins · Eli Perkins
Read full at Blog - Eli Perkins →
Opening excerpt (first ~120 words) tap to expand

Stop writing count ?? 0 in your UI code. Stop writing items ?? [] in your API return values. Please, for the love of god, stop writing item?.id ?? "", especially. Coalescing feels satisfying when you appease the compiler or typechecker, but what you're doing is introducing a ticking timebomb instead. I've been guilty of using each of these patterns over my career. What I should have done instead was understand why those values could be nil and handle them with some loud error or better yet, some UI that indicated these values were missing or loading or just plain empty still. I see so much UI code that defaults to these fallback values, rather than conditionally rendering a loading indicator, an error message or an empty state.

Excerpt limited to ~120 words for fair-use compliance. The full article is at Blog - Eli Perkins.

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from Blog - Eli Perkins