Conditional Rendering with Enum
In JavaScript an object can be used as an enum when the object is used as a map of key value pairs.
An enum is a great way to have multiple conditional renderings. Let's consider the notification component again, this time we can use the enum as inlined object.
The state property key helps us to retrieve the value from the object. It is much more readable compared to the switch case operator.
In this case we had to use an inlined object, because the values of the object depend on the text
property. That would be my recommended way anyway. However, if it wouldn't depend on the text property, you could use an external static enum too.
Although we could use a function to retrieve the value, if we would depend on the text
property.
After all, the enum approach in comparison to the switch case statement is more readable. Objects as enum open up plenty of options to have multiple conditional renderings. Consider this last example to see what is possible.