A
t
r
a
X

Contacts

Rr. Free Ukraine, Pallati Teknoprojekt, Kati 3, nr 2/2, Tirana, Albania

info@atrax.al

+355 69 21 46 615

Category: Software

Software

Microfrontends with React

It is common knowledge that the best method to tackle any software issue is to disassemble the problem. Whether it be by rewriting your code to create functions that are more manageable and clear, there are multiple ways to accomplish this.

Why use Micro Frontends?

Large applications have profited in multiple ways from the development of microservices, which have advanced in recent years. It is helpful in the process of efficiently developing, deploying, and scaling the separate components of the application backend.

Nevertheless, many developers have become aware that similar difficulties exist for the front-end as well. It is at this stage that the breaking up of the frontend monolith into individual micro front-ends usually begins.

Module federation (Module Federation | webpack)

Module Federation allows a JavaScript application to dynamically load code from another application and in the process, share dependencies. If an application consuming a federated module does not have a dependency needed by the federated code, Webpack will download the missing dependency from that federated build origin

I’ll create 2 apps in this article:

  • First: Container app that will be used as a base for the micro frontends.

  • Second: The counter app that will get rendered inside the container app.

Let’s update the webpack.config.js file inside the Counter app. Add ModuleFederationPlugin to the plugins array with the following configuration:

webpack.config.js

plugins: [ // This is important part
    new ModuleFederationPlugin({
      name: "counter",
      filename: "remoteEntry.js",
      remotes: {},
      exposes: {
        "./Counter": "./src/components/Counter",
      },
      shared: {
        ...deps,
        react: {
          singleton: true,
          requiredVersion: deps.react,
        },
        "react-dom": {
          singleton: true,
          requiredVersion: deps["react-dom"],
        },
      },
    }),
    new HtmlWebPackPlugin({
      template: "./src/index.html",
    }),

Let’s update the webpack.config.js file inside the Container app.

plugins: [ // This is important part
    new ModuleFederationPlugin({
      name: "container",
      filename: "remoteEntry.js",
      remotes: {
        counter: "counter@http://localhost:8081/remoteEntry.js",
      },
      exposes: {},
      shared: {
        ...deps,
        react: {
          singleton: true,
          requiredVersion: deps.react,
        },
        "react-dom": {
          singleton: true,
          requiredVersion: deps["react-dom"],
        },
      },
    }),
    new HtmlWebPackPlugin({
      template: "./src/index.html",
    }),
  ],

Now in src/App.js

import React from "react";
import ReactDOM from "react-dom";
import { Counter } from 'counter/Counter';
import "./index.css";
const App = () => (
  <div className="container">
    <h1>Container App</h1>
    <Counter /> // Micro frontend app
  </div>
);
ReactDOM.render(<App />, document.getElementById("app"));

If we run both apps, we should see Counter app inside of Container app working as it should.

Notice: both apps need to be running for Microfrontends to work.

Also in production you can update the app deploy url’s to remote server url.

That’s it.

Now you can split your apps into smaller, more manageable chunks.

Thanks for reading!

Software

How to render Big lists in React

Working with web apps we have to render tables or lists of data often. Most times lists do not contain many records and it is fine. However problems arise when app scales and now lists have thousands of records.

To solve this problem we can implement a paradigm called Virtualization

For starters let’s create a simple component which fetches 1000 records of photos.

usePhotos.tsx

import { useEffect, useState } from 'react';
import Photo from './Photo';
 
function usePhotos() {
  const [photos, setPhotos] = useState<Photo[] | null>(null);
 
  useEffect(() => {
    fetch('https://jsonplaceholder.typicode.com/photos?_limit=1000')
      .then((response) => response.json())
      .then((photosData) => {
        setPhotos(photosData);
      });
  }, []);
 
  return {
    photos,
  };
}
 
export default usePhotos;
And another component PhotosList to render each photo
import React from 'react';
import styles from './styles.module.scss';
import usePhotos from './usePhotos';
import PhotoCard from './PhotoCard/PhotoCard';
 
const PhotosList = () => {
  const { photos } = usePhotos();
 
  if (!photos) {
    return null;
  }
 
  return (
    <div className={styles.wrapper}>
      {photos.map((photo) => (
        <PhotoCard key={photo.id} photo={photo} />
      ))}
    </div>
  );
};
 
export default PhotosList;
While the above solution works, it is far from optimal.

Rendering 1000 div’s in DOM is not optimal at all.
This is where Virtualization comes in handy.

If we render a large list, the user does not see all its contents at once and uses a scrollbar. When we implement virtualization, we don’t render the elements of the list that are not currently visible. By doing that, we make the DOM tree creation a lot faster. Besides that, the browser does not need to fetch all the images simultaneously.

To implement virtualization in this article, we use the react-window library.

npm install react-window @types/react-window

PhotosList.tsx

import React from 'react';
import usePhotos from './usePhotos';
import PhotoCard from './PhotoCard/PhotoCard';
import { FixedSizeList } from 'react-window';
 
const PhotosList = () => {
  const { photos } = usePhotos();
 
  if (!photos) {
    return null;
  }
 
  return (
    <FixedSizeList height={800} width={600} itemCount={photos.length} itemSize={155}>
      {({ index, style }) => {
        const photo = photos[index];
        return <PhotoCard key={photo.id} photo={photo} style={style} />;
      }}
    </FixedSizeList>
  );
};
 
export default PhotosList;

Before & After Virtualization web site performance

Notice FixedSizeList has a defined row item width and height.

But it does not have to.

We can make it dynamic using another helper library.

npm install react-virtualized-auto-sizer @types/react-virtualized-auto-sizer

PhotosList.tsx

import React from 'react';
import usePhotos from './usePhotos';
import PhotoCard from './PhotoCard/PhotoCard';
import { FixedSizeList } from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';
 
const PhotosList = () => {
  const { photos } = usePhotos();
 
  if (!photos) {
    return null;
  }
 
  return (
    <AutoSizer>
      {({ height, width }) => (
        <FixedSizeList
          height={height}
          width={width}
          itemCount={photos.length}
          itemSize={155}
        >
          {({ index, style }) => {
            const photo = photos[index];
            return <PhotoCard key={photo.id} photo={photo} style={style} />;
          }}
        </FixedSizeList>
      )}
    </AutoSizer>
  );
};
 
export default PhotosList;

We can use AutoSizer to manage only width or height instead of both. To do that, we need to use the disableHeight or disableWidth  attributes.

That’s it.

Now you can render endless lists without worrying about performance.

Software

INTUITIVE UI.
WHAT DOES IT MEAN AND HOW CAN YOU DESIGN IT?

People everywhere and everyday use apps for all kinds of purposes. They use them for work, leisure, motivation, planning, socializing, learning, and the list could go on like this forever. Therefore, building a successful product that can stand out from the clutter becomes a real challenge. Consumers know right away when they don’t like using an app, and they can easily recognize when they actually love using one. What they fail to understand is that one of the main reasons they love using it, is because the app is intuitive.

So, if you’re a UX/UI designer, a developer, or a project manager, you should know what it means to build an intuitive app. How exactly can you build one when the concept of intuition itself is so vague?

 Every intuitive app revolves around one keyword: easy – easy to understand, easy to use, and easy to love. Although, the fact that it’s easy to use doesn’t mean that it’s simple to achieve.

 Throughout the whole building process, constantly think about one question: how will your consumers use the product. Everything you design or build should exist only to make your customer’s life easier.

 So, let’s take a look at a few things to keep in mind before you start designing a new app.

  • EASY TO DISCOVER
    The first interface sets the tone of your relationship with the app. A well-designed interface displays, from the first moment you open the app, all the main features in front of your eyes. Yet, everything looks clean and organized to avoid any chance of being overwhelming. Notifications, messages, settings, and all the main functionalities are within reach of your thumb for you to click and explore.
  • EASY TO UNDERSTAND
    You see a button with an envelope icon on top of it. Your intuition tells you that, most probably, that button will lead you to the messages section. You know the purpose of that button without having to click it first. The icon told you everything you needed to know.
    That is why, in an intuitive app, visual representation leads your journey as a user.
  • EASY TO PREDICT
    That leads us to the importance of predictability. When you click on a button, you already know that something will follow that action. For instance, if you click on a +, you expect that to give you the chance to add new items. If the prediction doesn’t happen, you become confused, and you are no longer satisfied with the product. Making the design so obvious makes the operation predictable, thus making the app intuitive.
  • EASY TO USE
    We’ve all used apps that make us go through tiring user flows, asking questions after questions, and moving us from one interface to another. So before you finish the task, you’re already annoyed and want to quit using the app. An intuitive product makes the flow efficient; it offers you what’s necessary, nothing less than what you need and nothing more. 
  • EASY TO INTERACT
    No one wants to click on a button and be left waiting and wondering without feedback. No reaction from the app might frustrate you. It might make you repeat the action over and over again and make you fail to complete it. That is why, for every action, there should be an immediate response that lets you know that the task has been successfully completed.
  • EASY TO FIX MISTAKES
    Using an app shouldn’t be so rigid; it should take into consideration your human flaws instead and help you correct them. Take Google, for example. When you search for a specific item and misspell the words, Google suggests the right options and the search engine still offers you the answers you were seeking. An intuitive app always offers solutions and solves your everyday mistakes.

Software

WHY IS OUTSOURCING IN ALBANIA A GREAT IDEA?


Outsourcing instead of having in-house software developers is, more than anything, a business choice. It helps you solve issues regarding time, money and skills. If it is well-organized, it can provide you with easy access to talented developers and hire good professionals at reasonable costs. But, like any business endeavor, first, you need to find the right partner.
What does “the right partnership” looks like? There are many different things, like for instance, we’re thinking that it looks like money, professionalism, and work ethics. Albania’s market can give you all that and more. So, let’s have a quick look at what this country in the middle of Europe, has to offer.

GREAT LOCATION

Remote working turns communication within teams into a real challenge. That is why you have to make sure you’re outsourcing developers from countries that share acceptable time differences with you.

Albania is situated in the southeast of Europe and is only a couple of hours away by flight from any country in Europe, Britain, and Israel. The country shares the same or similar time zones with these areas. The difference in time with the USA is approximately 6-9 hours. So, with this reasonable difference in time and proper remote team management, you can have full control over the implementation of the project.

A GROWING MARKET
There is a significant rise in software companies in the last years with several of them expanding internationally. The market is opening to foreign opportunities and it’s pushing more and more young Albanians to pursue a career in software engineering.

 SIMILAR WORK ETHICS

Regardless of certain cultural differences, the country is in the center of Europe and has close ties with the United States. So, Albanians, especially those working in the software development industry are very familiar with western work ethics.
Companies in Albania organize their daily tasks and manage their time and work relations the same way as any company situated in the west, making any kind of collaboration move on flawlessly.

EXCELLENT ENGLISH
Communication, the number one requirement of working with an outsourced remote team, is based on speaking a common language. Thankfully, young people in Albania, especially those into software and coding, due to their professional training, are usually fluent in English. This way there are no language barriers, and you can easily speak with your team and understand them.

BEST VALUE FOR MONEY

Everyone wants to hire the best developers, however not all companies can afford to do so. Outsourcing comes as the solution, although a good entrepreneur knows that outsourcing is not about hiring the cheapest developers. Outsourcing it’s about hiring the best with the money you have.

Like many western countries in Albania, you can find highly qualified professionals, but unlike other countries in the west, outsourcing in Albania can be profitable and inexpensive. Here you can find developers that offer top services at favorable prices.

Software

HOW TO BUILD A SUCCESSFUL DISTRIBUTED TEAM OF DEVELOPERS

Going back to just a couple of years ago, we all remember thinking of remote working as the vanguard future in the innovative industry of software development. That’s right… the future. Then Covid-19 happened, and the world had no other way to keep moving but remotely. We had no option but to make the future happen now… and strangely enough, it worked. Fast-forward today, tech companies, and startups all around the world have already adopted this new practice and are operating with full-scale distributed teams. In just two intensive years we’ve gathered a great amount of experience and we can now easily recognize the obvious benefits of working with remote teams as well as identify the challenges it poses. This experience has shown us that if addressed properly, we can overcome the difficulties and build great outsourced teams.

EDUCATE YOUR CLIENT
You’ve searched for a long time and you’ve finally managed to recruit new promising talents. Hang on a minute. Don’t rush to start working. Take some time to train your clients instead. They should be well aware of the process that waits for the project and how it will work. Make sure they understand that your goals are in line with their business goals and that the team you’ve built is there to build THEIR product.
Also, tell to them everything about the limitations related to working hours and availability, especially if you’re working in different time zones. Better do it earlier than later.

DISTRIBUTE THE TEAM
Finding the best fit for the specific project is great. It’s arranging them into teams, that is tricky! Are groups of 2-3 people too small? Are 9-10 people too much? Should you group them by their nationalities? There are no right or wrong answers, but experience has shown that teams of 5-6 people work best. Communication between them flows easier and each one of them understands better his specific role.

ESTABLISH A COMMUNICATION
Communication is without a doubt the biggest challenge that remote teams have to deal with. Talking at any moment and discussing things face-to-face is difficult when part of the team is in Asia, part in East Europe, and part in Israel. Use specific tools that will help you facilitate the communication. Choose from the beginning a platform that works best for you and your team and stick to it.
Establish core working hours. Since you are probably working in different time zones, you have to set up a minimum of 3-4 hours when all team members are available online. Discuss it with them prior, understand which hours work best for them, and be flexible. The important thing is to find the best solution for everyone.

SET UP CLEAR ROLES
You have to assign a specific role to each team member and clearly define their responsibility. Make sure they’ve understood what is expected of them, they know the tasks they have to complete and how to do them.

INTRODUCE A CLEAR ROADMAP
At the beginning of the project and throughout the process, you should have clear long-term and short-term goals and make sure all team members are aware of them. They should have a clear view of where the project is going. It’s important to set up precise mile-stone and deadlines.

SET UP A MANAGEMENT PROCESS
Dealing with a big project and managing several distributed teams at the same time can be an overwhelming endeavor. There are too many things to do and you should have control over all of them. That is why platforms like Backlog, Wrike, Monday, etc. can be a great tool for project management.

CREATE AND ENCOURAGE COMPANY CULTURE
Working for 8-hours straight inside an office with other colleagues helps create personal connections. Personal connection makes communication and collaboration between teams easier. Communication and human relations stand at the core of every company’s culture.
Even though with remote work building human relationships seems difficult, that doesn’t mean it is impossible. You should constantly organize team buildings, offline meetings, and outdoor activities whenever it is possible, even if not everyone can join.
Create a just culture among the teams and within each team. Make people feel appreciated for what they do. Make them feel safe to step up and share with you any mistake they’ve made. This way you’ll have the chance to fix it immediately instead of doing it much later when the problem is too big to go unnoticed.

In the end, when building distributed teams, you have to TRY, IMPROVE & TRY AGAIN. You have to be willing to improvise when needed and adapt your practice to whatever works best for the team and the project.