Is Learning ReactJS For You?
Tags: frontend, react, development
Published: 2019-04-02 21:18:28

---
title: Is Learning ReactJS For You?
published: true
tags: frontend,react,frontend,development
canonical_url: https://medium.com/yazanaabed/what-i-know-about-reactjs-87234f701381
---

[_ReactJS_](https://reactjs.org/) _is an impressive library to create things and build a user interface. Team form Facebook made it for us._

![](https://cdn-images-1.medium.com/max/1024/0*I2LVy4WMsn6Umd4R)<figcaption>Photo by <a href="https://unsplash.com/@frsphoto?utm_source=medium&amp;utm_medium=referral">Felix Russell-Saw</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

You can follow me on [twitter](https://twitter.com/YazanAabed) or check my latest articles on [my site yaabed.com](https://www.yaabed.com/). Also, I have my publication at [medium blog.yaabed.com](https://medium.com/yazanaabed).

Before I learn to React, I don’t know why people love working with it that much, and companies ask about it every frontend interview. Moreover, people told me that writing HTML in a separate file is the best practice for your project, now React team write the template on another way inside your JavaScript file.

There is too many questions come to your mind before you learn React. However, I decided to start learning React. After I learn React, I understand why we write the template in that way. It shows to me that React is the future for the web development, it changes how I think about developing web applications.

{% tweet 1003345768256819205 %}

You can learn to React by yourself. I recommend every front-end engineer to learn it. React extends your knowledge, especially how you think about your design, your components, your user interface, your application architecture.

In this article, I give an overview what I know about ReactJS and what I learn about it. I hope you enjoy reading this.

Watch this video to know five things about React. — [Dan Abramov](https://medium.com/u/a3a8af6addc1) & [Burke H✪lland](https://medium.com/u/d4377b6d15d2)

{% youtube 3DCeoCpTIAI %}

Before I start to discuss the building items for any React project, I recommend people to watch these courses:

- [The Beginner’s Guide to React](https://egghead.io/courses/the-beginner-s-guide-to-react) — [Kent C. Dodds](https://medium.com/u/db72389e89d8).
- [React For Beginners](https://reactforbeginners.com/) — [Wes Bos](https://medium.com/u/86a55cd7983b).
- [Complete Intro to React](https://frontendmasters.com/courses/react/) — [Brian Holt](https://medium.com/u/69ba9847d710).

I discuss the elements of any React application and where is the starting point for any application with React. Also, I give an overview steps to build any React application.

![](https://cdn-images-1.medium.com/max/1024/1*vV2mYuwX7lcZsncydIlvvw.png)<figcaption>This is my first React application 🔥✨</figcaption>

- We need to import React writing React application.
- We need to import the render function from react-dom.
- We need to define where to render our application using render method.

### Root Element

Any React application need a root container to start from it. render function give us the ability to render any React component to HTML DOM. The most thing I like about this render function is that you can test your application easy and render your application to fake DOM element with your testing library.

![](https://cdn-images-1.medium.com/max/1024/1*eXmNdsutdSN2npW2PpOzXg.png)

### Components

The component is a View in MVC. You divide your application as you see the application design. For example Header, SideBar, Button.

Also, a component could be a page or a container like Home, Login, Dashboard.

React application divided into multiple React components, and every component contains a render method which is the entry point for your component.

![](https://cdn-images-1.medium.com/max/1024/1*ZNLMhhwo0huzxojc1-0gtg.png)<figcaption>Paragraph component</figcaption>

React library use the render method to know what to render when you use the Paragraph component. And this is how we use our components inside our project.

![](https://cdn-images-1.medium.com/max/1024/1*WufN_zS7DKCe-xHK0dMhbA.png)<figcaption>Use Paragraph component</figcaption>

I recommend you try to build component by yourself or try to divide any design you got in your job to component and think why you divide it like that.

Make sure to understand this quote before you divide your application into components.

> “A component should, ideally, only be responsible for one piece of functionality.” —[ Fullstack React](https://www.fullstackreact.com/), [Sophia Shoemaker](https://medium.com/u/fac5e491c445) & [Nate Murray](https://medium.com/u/6538666cdb34).

{% tweet 1003312607418347521 %}

### Components contain two primary weapons

You can use these two weapons to make your component more reusable and more flexible.

#### Props

Props are the inputs for your component, owned by the component parent and passed from there. Any component use props more reusable than other components hide its values inside it.

![](https://cdn-images-1.medium.com/max/1024/1*R4ZiZ7yoeIjAvQk6Z7ygxA.png)

Props are the primary weapon for reusability because if we define the blogs array inside the Blogs component, can’t use in other places in the app or with other blogs values other places in our application needs.

These type of component that works only with props called stateless components. Every time you give the same component same input, it renders the same output or the same DOM.

Things to check when start working with props:

- [Type checking With PropTypes](https://reactjs.org/docs/typechecking-with-proptypes.html)
- [Components and Props](https://reactjs.org/docs/components-and-props.html)
- [Presentational and Container Components](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0) — [Dan Abramov](https://medium.com/u/a3a8af6addc1)

#### State

The component itself owns a state, a state can be modified using the component itself, or can be initialized using the props from outside.

The one place the state initialized is inside the constructor, after that you need to use a setState method from React.Component object to modify the state for your component.

![](https://cdn-images-1.medium.com/max/1024/1*c84rUbTht2PcCLMMZwytAQ.png)<figcaption>Login component contains its state and manages its state.</figcaption>

These two weapons could be your enemy if you don’t use them wisely, mainly when you use the setState method in wrong places and trigger re-render without any need. So, please think twice before you design your components and what to use. If the component doesn’t take a state and get the values from outside, it is more reusable this called stateless components if the component manages its state this called stateful components.

![](https://cdn-images-1.medium.com/max/1024/0*b3SyKELKooLlcupz)<figcaption>Photo by <a href="https://unsplash.com/@ay_leon?utm_source=medium&amp;utm_medium=referral">Leon Rojas</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

### Virtual DOM

React team modify things for us it doesn’t allow us to work with the browser DOM is built for us something called the virtual dom. React team take care of the changes with the DOM in an optimized way.

#### The problem with manual change for DOM:

- Hard to keep track for every change.
- It is slow for some cases to change the DOM using the JavaScript.
- The Facebook team gave a talk and said that JavaScript is very fast but modify the DOM is too slow.
- React team said that your component has to return the HTML you wish to see and react team take the responsibility from you to update the view for you.

The main reason that React team doesn’t take the state from the DOM because the DOM is too slow, so they decide to make the state change from their side.

> Why would we want to do that our component’s state from its DOM representation? There are two good reasons:

> 1) It’s faster, 2) It’s less complicated.— [REACT, REDUX AND JAVASCRIPT ARCHITECTURE](https://jrsinclair.com/articles/2018/react-redux-javascript-architecture/)

{% youtube NVWrdSz2Q5c %}

### Steps to build react project

First thing for React application is to divide your UI into components and make sure that every component do one thing and responsible for one thing.

When you build the application components, try to build the components with static values and make sure it works fine without any server or any BE.

Think which component of your application contains a state. Add static state for your component and try to change it. Add events trigger to move data around the component. After this add the server to your components.

### Timeline for React component

You can read more about React life cycle [here](https://medium.com/@baphemot/understanding-reactjs-component-life-cycle-823a640b3e8d).

- The constructor for the component is run, and the initial state now did.
- Then render method is called then call render for children to make sure to render the component.
- The initial render now run.
- The componentDidMount lifecycle is triggered.

### Routing with React

The user request the index.html page and then the server doesn’t care what the user does.

When you build the user router at the browser, this called a single page application.

React router: The app wrap with router provider when the route changed all component listen for the change and check if the path for is it renders else return null.

### Conclusion

Finally, I recommend every frontend engineer to give ReactJS a try; it is a fantastic library to build amazing applications. Don’t be afraid of these new things you can do it. Try to build things by yourself. Here is an [article](https://medium.com/hackteam/5-examples-of-react-applications-build-on-open-source-media-apis-c5b9880d922d) for ideas to learn to React using open source media APIS.