r/learnjavascript • • Jul 14 '21

5 Code Smells React Beginners Should Avoid

https://betterprogramming.pub/5-code-smells-react-beginners-should-avoid-480c97799162
1 Upvotes

4 comments sorted by

1

u/ChucklefuckBitch Jul 15 '21

Nice points, but I feel like point 3 is largely mitigated with the use of TypeScript.

The following snippet isn't a problem at all with TypeScript:

backgroundColor: props.status === 'active' ? 'green' : 'red'

If status is typed, then our compiler would tell us about it the moment there would be a problem.

That actually brings me to one of the biggest JavaScript code smells in my opinion: JavaScript itself. In my humble opinion, there are very few cases where there isn't a good reason to use TypeScript over JavaScript.

1

u/jasonleehodges Jul 15 '21

👏🏻 love this! We typically use TS enums instead of string literals. But I wanted to lower the mental overhead for this article so I left TS out of it.

2

u/ChucklefuckBitch Jul 15 '21

That definitely makes sense! I think the enum vs string literal discussion is much more subjective within a TS context, but of course within JS, enums win every day.

Thanks for the article, by the way. Was fun to read. Shared with some of the interns in my company

2

u/Achcauhtli Jul 14 '21

Thanks for sharing!