DEV Community

Cover image for React: Neatly hide conditional DOM elements ๐Ÿ‘€
Matt Shirlaw
Matt Shirlaw

Posted on

2 1

React: Neatly hide conditional DOM elements ๐Ÿ‘€

If you are anything like me you always cringe a little bit when you come across something like this in a React project ๐Ÿ˜ฌ

Without react conditional block

The more conditionals that you have, the worse it gets and the as people add more and more code over time it just gets worse and worse.

To solve this I always end up building a tiny wrapper component to hide this logic away. I'm sure other people do this sort of thing as well so I built a little npm package which will let you do this

With react conditional block

If you are interested you can get it on NPM. It certainly won't save you a heap of time but hey, a minute saved is a minute saved right ๐Ÿ˜œ

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more