Building Something From Scratch Phase at Encora Apprenticeship — Week 3

Ximena Sandoval
3 min readNov 30, 2021

--

Photo by Danist Soh on Unsplash

This post is part of a weekly assignment at Encora Apprentice and in this series, I’ll share my journey as a Software Engineer Apprentice. I hope these stories help and motivate others on their tech journey.

This week at Encora

As we are reaching the final week of this phase, I’ve been working a lot using React, a little bit of Express, and some experimentation using Docker. come to find more about it in this week’s essay!

React Hooks

As we continue to work with React, I got to learn more about Hooks, in particular, the State Hook and the Effect Hook. React Hooks allows us to use the state and other React characteristics without the need for a class. The State Hook looks like this:

import React, { useState } from 'react';const Example = () => {
/*This will declare a new state variable called count*/
const [count, setCount] = useState(0);
}

In the example, we are assigning the state variable 0, and to change it we can use the function setCount:

import React, { useState } from 'react';const Example = () => {
/*This will declare a new state variable called count*/
const [count, setCount] = useState(0);
...
setState(count + 1)
}

When we reach the line setState(count + 1) this will take the value of count and add it one and then set the new value of count with the function setState.

The Effect Hook tells the React component it needs to do something after rendering. Continuing with the example, we can have:

import React, { useState, useEffect } from 'react';const Example = () => {
/*This will declare a new state variable called count*/
const [count, setCount] = useState(0);
...
useEffect(() => {
document.title = `You clicked ${count} times`;
});
...
setState(count + 1)
}

With useEffect we can define an action that will take place after the first render and after each update (by default). In this case, each time the count variable is changed, it will change the title to the corresponding number.

So far, Hooks have been really useful since we can make our application more dynamic in a simpler way.

Systemd and Docker

While experimenting with Docker, I tried to install PostgresSQL to a Red Hat Linux container. In the process, I stumbled upon the fact that Docker containers don’t run Systemd by default, and thus, couldn’t start services such as PostgreSQL.

I was able to come with a solution to this problem, in specific with a Red Hat Linux image, you can run the following:

docker run -it --rm --privileged --name redhat registry.access.redhat.com/ubi8/ubi-init

But because of this approach, we won’t be able to use bash in order to install the required service, to do so we need to use another terminal and run the command:

docker exec -it redhat bash

This will open a bash shell in the container we started before, and then, we can run the script to install and start PostgreSQL:

chmod +x install_postgresql_script.sh
./install_postgresql_script.sh

Optimism Bias

Finally, I got to watch Tali Sharot talk about the Optimism Bias, and how it can help us live a happier life, but also lead us to dangerous or preventable situations. We are biased towards feeling optimism about ourselves and our futures, but not so much about others. The main takeaway from this talk was the need for balance between being optimistic and realistic in order to achieve our goals.

Final thoughts

This past week was full of learning and using more of React while working with a client’s project, and also writing scripts to install tools and services in many different OS. One of the main lessons I got from this week is the importance of the ability to search and find solutions for current errors and make sure to know how to troubleshoot in a smart way.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ximena Sandoval
Ximena Sandoval

Written by Ximena Sandoval

Cloud Platform Engineer at Encora. Currently learning about CI/CD, Kubernetes and watching Studio Ghibli movies✨

No responses yet

Write a response