Skip to content
Advertisement

How Can I Simplify This JSX Conditional Code?

I´ve got this code snippet:

JavaScript

where “buttonsType” is those enums:

JavaScript

I´d like to know some better way, to simplify the conditional statement. Or is it possible to have it like this?

Thank you.

Advertisement

Answer

I think Ray Hatfield’s answer is the cleanest solution and avoids repetitive JSX, but I’ll add a switch example as an option. Ternary generally seems like a poor option for this case.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement