Class Component vs Functional Component
Published: 2023-12-04 01:43:44

## Mattermost 
I recently contributed to the [Mattermost](https://github.com/mattermost/mattermost) project. Mattermost is an open source platform for collaboration across the software development life cycle, and it is written in React and Go. I chose this project because I wanted to work on a big React project with lots of contributors.

## The Issue
The issue I chose was about converting a class component to a functional component in React without changing its core functionality, and updating the relevant test cases to reflect the conversion. The issue can be found [here](https://github.com/mattermost/mattermost/issues/25600). The reason that they wanted to change their components from class to functional was based on React's recommendation and also functional components look to be cleaner, simpler, easier to write and maintain, and there is more support for them through the use of Hooks.

## The Process
### Setup
The most challenging part of the process for me was setting up the development environment. First, I had to install WSL on my machine which was done through the command `wsl --install` in Powershell. Then, I needed to install Docker Desktop to run the application. I followed the instructions from this [link](https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers#install-docker-desktop) to install Docker Desktop, however I was getting errors running Docker Desktop and Ubuntu. After doing some research I realized that I had to enable virtualization in bios and enable WSL integration for Docker Desktop. I followed the instructions from this [link](https://support.bluestacks.com/hc/en-us/articles/360058102252-How-to-enable-Virtualization-VT-on-Windows-10-for-BlueStacks-5) to enable virtualization on my machine and the picture below shows where to enable WSL integration for Docker Desktop 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ev3km87gm1mlg5knwenf.png)
Afterwards, I installed Go in my WSL environment, increased the number of available file descriptors by using the command `ulimit -n 8096`, installed "libpng" in the WSL, forked and cloned the project, installed NVM and used `nvm install` to install the correct version of Node.js for the Mattermost web app. After this I was able to run the server and the webapp.
### Changes
First, I had to do a quick review on my React knowledge and the implementation of class components vs functional components, then I familiarized myself with the Jest testing framework. After that I implemented the conversion and updated the test file associated with that component. The changes that I made can be found in the screenshots below:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ucqq1ff4ksdi34uxg6p6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wol6h2bu9uxrggl7tfuj.png)
Finally, I completed the Mattermost's CLA, committed my changes, and created a [PR](https://github.com/mattermost/mattermost/pull/25614) to be reviewed.

## What I learned
Like I said the most challenging part for me was setting up the development environment, since I have never worked with WSL and Docker before. I learned how to set up WSL on my machine, use Docker Desktop for containerized applications, and work with Jest framework. This was also a nice review on my React knowledge, which was very needed since I have been focused on working with C# lately.