Common Mistakes When Starting as a Front-End Developer

introduction

Getting started in the world of front-end development is exciting, but it's also full of challenges. Making mistakes is part of learning, and while frustrating at first, every mistake brings an important lesson. Whether you work with React, Next.js, TypeScript or more general approaches, learning from these challenges can take you to a more advanced level quickly.

In this article, I share some common mistakes I faced when I started, how I solved them, and what I learned from them. I hope they will help you to avoid tripping over the same stones!

Common Errors in React

Making mistakes in React, Next.js and TypeScript is inevitable... but each one brings an important lesson.

1. Poor state management in complex applications

When I started with React, I used UseState to handle any type of data. This worked for small projects, but as I scaled my applications, maintaining consistency between states became a nightmare. My components rendered more than necessary and the data became inconsistent.

Example:

A large form handled the state of each input independently with UseState. This caused multiple unnecessary renders, slowing down the application.

Solution:

I learned to use tools such as UseReducer for complex local states and bookstores like RTK Query to efficiently handle asynchronous data. This organization reduced renders and facilitated scalability.

Lesson:

Not all applications need advanced solutions, but for more complex projects, planning state management from the start is crucial.

2. Incorrect use of rendering methods in Next.js

Next.js makes server-side rendering (SSR) a lot simpler, but at first, I didn't quite understand when to use GetStaticProps, GetServerSideProps or getStaticPaths. This led to less efficient applications and unnecessarily long load times.

Example:

I implemented GetServerSideProps on pages that didn't require constant dynamic updates, wasting resources.

Solution:

  • I used GetStaticProps for static pages such as blogs or product catalogs.
  • I implemented ISR (Incremental Static Regeneration) for pages with dynamic data that didn't need real-time updates.
  • I reserved GetServerSideProps for pages where data freshness is essential, such as dashboards.

Lesson:

Understanding how and when to use the rendering methods in Next.js can improve performance and user experience.

3. Ignoring the power of TypeScript

In the beginning, I used TypeScript in a basic way, with generic types such as Any or Unknown, without exploiting its full potential. This allowed silent errors to manifest in production.

Example:

I defined a state with Any, allowing for unexpected values that broke the component:

Solution:

  • I explicitly typed the data structures from the start:
  • I used utilities like React.FC and AxiosResponse for typing asynchronous components and functions.

Lesson:TypeScript not only helps prevent errors, but it improves team collaboration by making it easier to understand the code.

4. Don't optimize images in Next.js

In an e-commerce project, I forgot to use the component next/image, resulting in long charging times, especially on mobile devices.

Example: Upload images directly to the public directory without compressing them or adjusting their sizes.

Solution:

  • I implemented next/image for automatic optimization, modern formats such as WebP and lazy loading.
  • I set up a CDN to deliver the images faster.

Lesson:
Optimizing images and resources is essential to improve the user experience, especially in projects with high visual content.

5. Errors in dynamic routes

When working with dynamic routes and getStaticPaths, did not properly validate the data, causing 404 errors in production.

Example:

I forgot to handle cases of non-existent IDs, leaving users with a broken page.

Solution:

  • I implemented validations in the backend and used fallback: true to handle routes that are not dynamically generated:

Lesson:

Dynamic routes require careful validations to avoid broken experiences.

General Front-End Errors

Front-end development is not limited to working with specific libraries or frameworks; it also involves applying good design and optimization practices to ensure that applications work well on any device and provide an enjoyable user experience. Here are some of the most common errors and how to fix them.

1. Use fixed measures instead of responsive units

One of the most common mistakes among beginners is to use absolute measures such as px to define element sizes in the interface. Although it may seem simple at first, this limits the flexibility of the design and makes it incompatible with screens of different sizes.

Instead, it's better to go for responsive units like %, In or Rem, which allow elements to be automatically adjusted depending on the size of the container or screen. Complementing this with media queries ensures that the design is adaptable and functional at any resolution.

2. Don't design with responsiveness in mind

It's easy to forget that web applications will be viewed from a variety of devices: from phones with small screens to large monitors. Designing only for a fixed resolution can lead to a poor user experience.

The solution lies in taking an approach Mobile-first, where the design is first built with mobile devices in mind and then adapted to larger screens. Tools such as Flexbox and CSS Grid facilitate the creation of responsive and organized designs. In addition, regularly testing the design in different resolutions and devices will help you identify problems early.

3. Relying too much on CSS frameworks

Frameworks like Bootstrap or Tailwind CSS can be useful tools for accelerating development, but relying completely on them without understanding the fundamentals of CSS can be a costly mistake. This can limit the customization of designs and make it difficult to resolve specific problems.

Learning the basics of CSS is essential for greater control over the design. Once you master the basics, frameworks can be used as support tools, but not as the only solution.

4. Ignore unit tests

The lack of unit testing can lead to serious errors in production, especially when projects grow in complexity. It's common for beginning developers to not implement tests because they think they're unnecessary or complicated.

Unit tests, carried out with tools such as Jest or React Testing Library, help ensure that each component or function works properly before deployment. Implementing them from the start not only improves the quality of the code, but also prevents major problems in the future.

5. Don't use a version control system

Working without tools like Git makes it difficult to track changes made to a project and recover previous versions in case of errors. This problem is especially critical when working as a team.

Adopting Git from the start is a fundamental practice. Learn basic commands, such as Commit, Branch, and Merge, will allow you to better organize your workflow, collaborate with other developers and manage versions efficiently.

Common mistakes when using Git

Even when using Git, it's easy to fall into poor practices. Some common errors include:

  • Incorrect branch merging: Failure to merge properly can cause conflicts that are difficult to resolve. It uses commands such as Git Merge and git rebase carefully and be sure to review the changes before confirming.
  • Undo changes without caution: Commands such as Git reset or Git revert should be used clearly about their impact. Before you undo something, review the commit history with Git log.
  • Disorganization in workflows: Adopting clear flows such as GitFlow or trunk-based development improves collaboration and avoids chaos in large projects.

Mastering Git from the ground up will give you the confidence to handle any situation in your projects.

6. Neglecting resource optimization

A common mistake is to upload uncompressed images, not to minify CSS and JavaScript files, or not to implement techniques such as lazy loading. This can cause long load times, negatively affecting both the user experience and SEO.

To solve this problem, use tools such as Lighthouse to audit the performance of your application and apply strategies such as the use of modern image formats (WebP), file compression and the reduction of unnecessary HTTP requests. Implementing these practices will make your application faster and more efficient.

Conclusion

General front-end errors often arise from a lack of experience or a lack of knowledge of key good practices. However, correcting them in time and taking a more conscious approach to development will make a difference in the quality of your projects. By applying responsive measures, optimizing resources, and using tools such as Git and unit testing, you'll be one step closer to creating robust and professional applications.

Karla Cabañas

December 11, 2024