This is a good one too. In the case of TypeScript, we do loose a bit of type checking (you can leave the default case off if the possible values are an enum IIRC), but this is good too.
I've really grown fond of using this approach in React specifically, since we can't have normal conditionals inside of JSX:
This is a good one too. In the case of TypeScript, we do loose a bit of type checking (you can leave the
defaultcase off if the possible values are anenumIIRC), but this is good too.I've really grown fond of using this approach in React specifically, since we can't have normal conditionals inside of JSX: