Better Programming

Advice for programmers.

Follow publication

5 Code Smells React Beginners Should Avoid

Make sure to double-check your pull request for these things before you submit

Jason Lee Hodges
Better Programming
Published in
8 min readJul 14, 2021

--

Woman blocking her face
Photo by Priscilla Du Preez on Unsplash.

As a mentor to frontend beginners who have come from a myriad of different backgrounds, including bootcamps and other non-traditional education paths, I have observed many different approaches to coding in React. Part of the beauty of React is that it is generally pretty unopinionated relative to frameworks like Angular and Vue. This makes it flexible enough to plug into lots of existing code bases written in different frameworks. Additionally, it inspires a plethora of community libraries for different use cases, thereby pushing the whole industry forward.

However, the downside to convention-agnostic, configuration-heavy ecosystems is that it leaves a lot of room for beginners to stray from best practices. Below are five oft-violated best practices — or code smells — that I often find when reviewing pull requests from new React developers.

It should be noted that a “code smell” in this context is just a pattern I notice that draws my attention for further scrutiny. It does not mean that these are always improper implementations. There are no absolute rules in good software engineering. Every one of these code smells could make sense given the proper context in exceptional circumstances. That being said, if you find yourself using these patterns, you should stop and ask yourself, “Is this really necessary?”

1. Mutable Variables

In the past five years, I have only had to use a mutable variable once — like I said, there is an exception for every best practice. Mutable variables are variables that can be re-assigned throughout the execution of your code. Those variables in JavaScript are let and var. If you are using ES6 syntax, you likely will never want to use var, but I still find many React beginners using let.

When reviewing a pull request, seeing any variable that is not a const variable in React informs me that the developer is likely most familiar with procedural design patterns. The Accumulator Pattern is one such example of a procedural design pattern utilizing a mutable variable that I see many beginners using. Almost every design pattern that uses a mutable variable can be…

--

--

Jason Lee Hodges
Jason Lee Hodges

Written by Jason Lee Hodges

Economist and Author of “Software Engineering From Scratch.” Director of Engineering at Domo. Science, Technology, Sci-Fi, and Art Enthusiast.

Responses (17)

Write a response