DEV Community

Cover image for How not to write clean code in React? 🧹
Avneesh Agarwal
Avneesh Agarwal

Posted on • Updated on

How not to write clean code in React? 🧹

Introduction

Wassup everyone, long time no see. Today we will see a few ways to not clean code in React, let's jump right into it!

Jump right into it

10 ways to not write clean code

Not use a linter

Who needs a linter to keep good code styles, and keep the code clean when you can define the rules as you go. 🚨

Add everything in one file

Just put everything in one file, so you don't need to create many different files and components and can have 1000s of lines in one file. The compilation build time will also be very small if you use just a single file! 🙈

Write duplicate code

Why reuse variables, and components when you can copy-paste the same code over and over again and if you need to change one small thing then spend a ton of time adjusting it everywhere. So productivity++ 😌

Have unused imports/variables everywhere

Why care to delete the unused variables and import them when they can stay where they are and increase your app bundle size. 📈

Prop drilling

Just keep passing props 10 components deep because who wants to use a tool to manage state properly 🥱.

Not destructure objects

Who cares about destructuring objects, keep doing {object.a}, {object.b} everywhere. 🧐

Not using typescript

Who needs to use typescript when you can pass a number for name somewhere and string for the same variable somewhere 🤷‍♂️

Not using enums

Who doesn't love typos!? Why use enums when you can make a typo and mess up your entire code base and pull your hair for 2 days to find the error after breaking production 🤡

Use random names for functions, variables, components

Why waste time thinking about a great function/variable/component name, use a random name and save time. 🕰

Conclusion

I hope you were able to understand how not to write clean code, now it is up to you to choose if you wanna write good code or bad code! That's it for this one ✌️

Useful links

How to not become a better developer

Connect with me

Top comments (0)