re: A New Coding Style for Switch Statements in JavaScript/TypeScript VIEW POST

TOP OF THREAD FULL DISCUSSION
re: ATM I prefer not writing switch statements and instead use conditional return statements like const myFunction = () => { // ... return ( ...
 

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:

<div>
  {body.type === 'isBasic' && <BasicComponent />}
  {body.type === 'isCustom ' && <CustomComponent />}
</div>
code of conduct - report abuse