Clean Code vs. Dirty Code: React Best Practices

Clean #Code vs. Dirty Code: #ReactJS Best Practices:  by @donavon #JavaScript

  • This article will focus on clean code practices as they apply to modern React software development.
  • Many React developers rely on Jest for a zero-configuration test runner and to produce code coverage reports.
  • And don’t discount the “rewrite factor” and time spent fixing comments from code reviews.
  • The advantage of letting React set your prop defaults, however, is that it produces more efficient code, defaults props in a based lifecycle component, as well as allows your default values to be checked against .
  • For example, the following component is ripe for converting to an SFC. – – The clean version clears a lot of the screen clutter of the dirty version.

Clean code is a consistent style of programming that makes your code easier to write, read, and maintain. Discover how to make your React code cleaner using easy-to-follow examples.

This article will focus on clean code practices as they apply to modern React software development. I’ll also talk about some of the “sugar” that ES6/ES2015 brings to the table.

What is clean code, and why do I care?

Clean code is a consistent style of programming that makes your code easier to write, read, and maintain. Often a developer spends time on a problem, and once the problem is solved, they make a pull request. I contend that you aren’t done just because your code “works.”

Now is your chance to clean it up by removing dead code (zombie code), refactoring, and removing any commented-out code! Strive for maintainability. Ask yourself, “Will someone else be able to understand this code six months from now?”

In simpler terms, write code that you would be proud to take home and show your mother.

Why do you care? Because if you’re a good developer, you’re lazy. Hear me out – I mean that as a compliment. A good developer, when faced with a situation where they have to do something more than once, will generally find an automated (or better) solution to complete the task at hand. So because you’re lazy, subscribing to clean-code techniques will decrease the frequency of changes from pull-request code reviews and the need to come back to the same piece of code over and over.

Clean code passes the “smell test”

Clean code…

Clean Code vs. Dirty Code: React Best Practices