avatarCharly Poly

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2544

Abstract

div><h3>Ease change: future-proof component code</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*1l33EYIJhJQfIVkqLVoEtg.png)"></div> </div> </div> </a> </div><h2 id="914b">Part III: Testing strategy and testable components</h2><ol><li>The many ways to test React code</li><li>A good testing strategy example</li><li>Make your components testable</li></ol><div id="d7bd" class="link-block"> <a href="https://readmedium.com/build-maintainable-react-apps-part-iii-9cef8777d606"> <div> <div> <h2>Build maintainable React apps — Part III</h2> <div><h3>Testing strategy and testable components</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*1l33EYIJhJQfIVkqLVoEtg.png)"></div> </div> </div> </a> </div><p id="3b46"></p><p id="b601">I hope that you will find those tips and best practices useful and that they will inspire you new approaches to keep your React applications maintainable.</p><h1 id="d026">TLDR;</h1><p id="6a8b">Maintainability is all about finding ways to keep your application in movement. However, every company operates at a different speed, which impacts the priorities of the technical decisions on the covered subjects.</p><figure id="cfcf"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*myLFvXIZ0WTqQI7xaG154A.png"><figcaption></figcaption></figure><p id="0b9e"><b>An early-stage startup</b> might want to iterate fast and break things to get to product-market fit, resulting in a bigger time investment on “future proof components” that are easy to refactor (ex: duplicated code), however, testing will be less a priority.</p><p id="e37e"><b>A late-stage startup</b>, most likely composed of a bigger engineering team and more demanding clients, might invest more in code organization and testing to guarantee the quality of the product.</p><p id="7908"></p><p id="5996">You will find below a summary of the principles of these articles; it is now your time to choose which ones are a priority for your business and build your architecture principles!</p><h2 id="7a9d">On code organization</h2><ul><li><b>Identifying the parts (domains) of your applicati

Options

on</b> will help to shape a better architecture (ex: state).</li><li>Investing a small amount of time in finding a <b>proper component’s name</b> is an excellent design exercise that will bring consistency (location and well-defined responsibilities)</li></ul><h2 id="00e9">On component code</h2><ul><li><b>Custom hooks are an excellent alternative to the Container/View pattern. </b>Let your component focus on UI aspects.</li><li><b>Ensure your component relies directly only on data that is displayed; otherwise</b>, use a business logic helper, custom hooks.</li><li><b>Beware of bad abstractions; they</b> are the most likely to prevent change.</li><li><b>Decomposition patterns</b> and the UI provided by your Product Designer are a good starting point to build well-defined components</li></ul><h2 id="cd62">On testing</h2><ul><li><b>React applications can be tested in many useful and different ways: </b>E2E tests, Integrations tests, Unit shadow rendering tests, Unit business logic tests</li><li>Invest time in testing the most important part of your product by <b>defining a testing strategy</b></li><li><b>Make sure your component can be tested easily</b> by avoiding coupling and components embedded in business logic.</li></ul><p id="bd40"><b>Follow me on Twitter</b> to stay up to date on React, GraphQL, and TypeScript!</p><div id="6a30" class="link-block"> <a href="https://twitter.com/whereischarly"> <div> <div> <h2>Charly Poly</h2> <div><h3>The latest Tweets from Charly Poly (@whereischarly). Helping you to get the most of new web-technologies ✍️🎙. Paris…</h3></div> <div><p>twitter.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*e6W6ZZqGI5DUtwjY)"></div> </div> </div> </a> </div><p id="17e3">This series is based on a talk I did at the <a href="http://geekle.us/">Geekle</a> April 2020 conference:</p><figure id="a873"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*NzwAYGgPBnFZQVaz"><figcaption><a href="https://noti.st/charlypoly/GlaLFs/maintainable-react">https://noti.st/charlypoly/GlaLFs/maintainable-react</a>, video available on <a href="https://youtu.be/4w_cEAkhp48">https://youtu.be/4w_cEAkhp48</a></figcaption></figure><p id="e6cc">❤️ to <a href="undefined">Louis Lafont</a> and <a href="undefined">Jonas</a> for reviewing the series!</p></article></body>

Build maintainable React apps — Series

Good practices and tips for maintainability

Photo by Omar Flores

The complexity of front-ends drastically increased in the last 20 years; we went very quickly from widgets JavaScript to Single Page Applications. The pace is still fast, we went from Redux to Mobx and now React hooks in the span of only a few years, making it more than ever essential to welcome change in our applications.

From widgets to applications

With React — and libraries from the eco-system — solving most of the challenges of modern front-end architecture (performance, rendering, state management), our primary mission as Front-end Engineers is to build and scale applications in a sustainable way, in other words, in a maintainable way.

The “Build maintainable React apps” series is composed of 3 parts:

Part I: Keep your application organized

  1. Break down your application in meaningful parts
  2. Reflect the defined application parts in code organization

Part II: Ease change: future-proof component code

  1. State management
  2. Loosely Coupled Component
  3. Components decomposition patterns
  4. Enable React warning and keep your dependencies up-to-date

Part III: Testing strategy and testable components

  1. The many ways to test React code
  2. A good testing strategy example
  3. Make your components testable

I hope that you will find those tips and best practices useful and that they will inspire you new approaches to keep your React applications maintainable.

TLDR;

Maintainability is all about finding ways to keep your application in movement. However, every company operates at a different speed, which impacts the priorities of the technical decisions on the covered subjects.

An early-stage startup might want to iterate fast and break things to get to product-market fit, resulting in a bigger time investment on “future proof components” that are easy to refactor (ex: duplicated code), however, testing will be less a priority.

A late-stage startup, most likely composed of a bigger engineering team and more demanding clients, might invest more in code organization and testing to guarantee the quality of the product.

You will find below a summary of the principles of these articles; it is now your time to choose which ones are a priority for your business and build your architecture principles!

On code organization

  • Identifying the parts (domains) of your application will help to shape a better architecture (ex: state).
  • Investing a small amount of time in finding a proper component’s name is an excellent design exercise that will bring consistency (location and well-defined responsibilities)

On component code

  • Custom hooks are an excellent alternative to the Container/View pattern. Let your component focus on UI aspects.
  • Ensure your component relies directly only on data that is displayed; otherwise, use a business logic helper, custom hooks.
  • Beware of bad abstractions; they are the most likely to prevent change.
  • Decomposition patterns and the UI provided by your Product Designer are a good starting point to build well-defined components

On testing

  • React applications can be tested in many useful and different ways: E2E tests, Integrations tests, Unit shadow rendering tests, Unit business logic tests
  • Invest time in testing the most important part of your product by defining a testing strategy
  • Make sure your component can be tested easily by avoiding coupling and components embedded in business logic.

Follow me on Twitter to stay up to date on React, GraphQL, and TypeScript!

This series is based on a talk I did at the Geekle April 2020 conference:

https://noti.st/charlypoly/GlaLFs/maintainable-react, video available on https://youtu.be/4w_cEAkhp48

❤️ to Louis Lafont and Jonas for reviewing the series!

React
Reactjs
Testing
Software Architecture
Naming Conventions
Recommended from ReadMedium