DEV Community

21 Best Practices for a Clean React Project

Mohammad Faisal on August 03, 2023

To read more articles like this, visit my blog React is very unopinionated about how things should be structured. This is exactly why it’s our res...
Collapse
 
kspshnik profile image
Evgeny Karpel

Using "style" intristic prop is a huge source of misstyling. Imagine you have 35 div's with same styling and you need to change just one or two properties of it. Writing a CSS class is way more better and convenient.

Collapse
 
future_inventor profile image
Maddo.Traveller

That was my initial thought as well.

Collapse
 
eyalandomer profile image
Maros Majba

If anyone would be willing to answer my questions about the seventh point in the article "Put CSS in JavaScript". I never understood why is JavaScript styling more sought after as CSS styling in React development. In my experience when I split the application into manageable components and pages CSS becomes much more manageable as pure JavaScript styling or styled components, even without introducing SCSS. And this rabbit hole just becomes even deeper when we introduce a component library such as Material UI. Why do they bother introducing quadrillion ways of styling their components instead of making it simpler with CSS styling, it just doesn't make any sense to me.

Collapse
 
lakshmananarumugam profile image
Lakshmanan Arumugam

Good article dood!

I love this article. Now a days instead of writing code, write a code with best practice is a far one.

I also share my experience and best practices in typescript and javascript to everyone for learning.

Keep it up!

Collapse
 
mohammadfaisal profile image
Mohammad Faisal

Yes... best practices are kindof lights in a runway.... not the runway itself.

And in my experience, yes you can always use the linter and prettier to fix most things.
But does it hurt to know why these rules are there in the first place? :)

Collapse
 
lausuarez02 profile image
Lautaro Suarez

Really good tips mate.

Keep the good work ;) !

Collapse
 
junedkhandev profile image
Juned Khan

Great Post Faisal!❤👋

I Like how you explained with examples! 👏

 
mohammadfaisal profile image
Mohammad Faisal

Agreed. But it's hard to prove these things :P

Collapse
 
ilumin profile image
Lumin

Use memo in the early stage of development is anti-pattern and might cause you trouble. So, use it when you're really needed it.

Collapse
 
mohammadfaisal profile image
Mohammad Faisal

I agree... this is just nice to know that you have it in your arsenal... when you need it.

Collapse
 
anedomansky profile image
Alexander Nedomansky

Thank you for this nice article!
I have one question about point 7 though:
I always keep my JS separate from my CSS, so I put everything in its own file.
This, to me, feels like a nice separation of concerns and I found that there are quite a few articles that criticize CSS-in-JS:

dev.to/srmagura/why-were-breaking-...
dev.to/xantregodlike/css-in-js-why...
freecodecamp.org/news/you-dont-nee...
dev.to/macsikora/css-in-js-did-we-...

What is your stance regarding this topic? :)

Collapse
 
mohammadfaisal profile image
Mohammad Faisal

Yes... but at the same time libraries like tailwind css has become much more popular...

I think this can vary from person to person. If separating css works for your project's scale and improves productivity, then why not?

There is no silver bullet! :D

Collapse
 
l2aelba profile image
l2aelba • Edited
<div>    or    just use        ESLint and                TypeScript?  😂😂    😂           </div>
Enter fullscreen mode Exit fullscreen mode