Pratham Profile picture
28 Jun, 24 tweets, 5 min read
Introduction to React and React Hooks β†ͺ️

React is a JavaScript library for building UI components. And Hooks are the heart of any React app. Let's talk about them.

πŸ§΅πŸ‘‡πŸ»
Why React?

1. Reusable components
2. Fast due to virtual DOM
3. Huge ecosystem

{ 2 / 23 }
A typical React app contains many components. They are reusable and can interact with each other.

What is a component?
- Component is a simple function that you can call with some input and they render some output

{ 3 / 23 }
Attached image showing a typical React app with all different components.
As you can see this entire webpage is nothing but a mixture of different components

{ 4 / 23 }
Components are of two types:

1. Class based components
2. functional-based components

Class-based components are defined using ES6 classes, whereas function components are basic JavaScript functions

{ 5 / 23 }
Before diving deeper into it, let's talk a little bit about JSX

- JSX stands for JavaScript XML. It's basically nothing but the extension of JavaScript which allows us to write HTML code in a JavaScript file.

{ 6 / 23 }
const element = <h1>Hello, world!</h1>;

Consider this variable declaration. It's neither JS nor HTML. This is the mixture of JavaScript + XML = JSX

{ 7 / 23 }
Now we know JSX, let's move forward

- Functional components are nothing but simply a JavaScript function that takes some parameter will return some JSX code

A typical function component πŸ‘‡πŸ»

{ 8 / 23 }
A very important concept in React

Virtual DOM

You might have heard the term "DOM", virtual DOM is kind of similar. It uses a strategy that updates the DOM without having to redraw all the webpage elements.

{ 9 / 23 }
Every time the DOM changes, the browser needs to recalculate the entire layout and then repaint the web page which makes a web app slow

To overcome this we have virtual DOM
Every time the state of our application changes, the virtual DOM gets updated instead of the real DOM

10
Whenever the new element is added to the UI, a new virtual DOM associated with that element is created. If state of this element changes, a second new virtual DOM is created which will be compared with the previous virtual DOM

- It then updates ONLY the object on the real DOM
Setting up your first react project directory is quite confusing. Let's see how you can do it

I'm assuming you have node environment set up and up-to-date version of npm. If no, download it from here

nodejs.org/en/

{ 12 / 23 }
Next thing you need to install is `create-react-app` is a tool helps you start building with React app. It set up all the tools that you need in order to get started.

{ 13 / 23 }
Now you have create-react-app installed in your machine, it's time to create your first React app

Command - "create-react-app app-name"

Depending upon your internet speed, this will take some minutes. So time to prepare a coffee for yourself.

{ 14 / 23 }
Once done, run "npm start"

Your default browser will launch automatically and you will see something like this at localhost:3000

{ 15 / 23 }
I think that's enough for the introduction. Let's move React Hook now. Starting with the discussion on some key point about React hooks πŸ‘‡πŸ»

{ 16 / 23 }
What exactly hooks are?

- We can consider hooks as a JavaScript function that takes some parameter and return something accordingly. But they servers some complex functionality like managing state and other React features.

{ 17 / 23 }
Hooks are backwards-compatible!

Backwards compatibility is the characteristic of a technology that allows for interoperability with an older legacy system. Hence hooks don’t contain any breaking changes.

{ 18 / 23 }
Did Hooks make any changes?

React concepts are the same irrelevant of a class component or functional component. Hooks can make the code shorter and they provide a quick and efficient way to combine state, props. lifecycle etc...

{ 19 / 23 }
Some points to consider while working with hooks!

- Don’t call Hooks inside loops, conditions, or nested functions
- Call hooks from React function components

{ 20 / 23 }
Here is the complete guide to widely use state in React



{ 21 / 23 }
With that being said, this is the end of this thread.

Wait!!

50% on my new eBook and 1-1 session
⚑ free50 ⚑

πŸ”— gum.co/100K-audience

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Pratham

Pratham Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Prathkum

25 Jun
Next 27 tweets are the Complete Introduction to CSS Grid Layouts including everything

πŸ§΅πŸ‘‡πŸ»
Grid is used for making complex web design layouts more easily as it's not so hard to master

Using Flex you can make only 1D layout but Grid gives you the full power of creating a 2D layout

Let's start

{ 02 / 28 }
First things first, start with giving the display property "grid" to the container element or parent element.

{ 03 / 28 }
Read 28 tweets
25 Jun
Cool things you can do with CSS only

🧡 πŸ‘‡πŸ»
Text portrait

πŸ”— codepen.io/prathkum/pen/x…
Texture portrait

πŸ”— codesandbox.io/s/texture-port…
Read 5 tweets
23 Jun
I have created enormous handmade notes for Web development beginners.

Here are some of my handmade JavaScript and CSS notes/cheat sheets that can help you 🧡 πŸ‘‡πŸ»
0. Semantic HTML
2. CSS border-radius
Read 13 tweets
23 Jun
Let's talk about some CSS concepts that we rarely used but they will prove that CSS is so deep.

πŸ§΅πŸ‘‡πŸ»
1. Select grammatical errors

::grammar-error pseudo-element select a grammatically incorrect sentence. Although this feature has not been standardized yet.

πŸ”— developer.mozilla.org/en-US/docs/Web…
2. You can optimize the performance of your web page by adding one line of CSS

The `will-change` property

- will-change tells the browser that how an element is expected to change
- Increase the responsiveness
Read 7 tweets
23 Jun
I again brought 5 awesome GitHub repositories for beginners

πŸ§΅πŸ‘‡πŸ»
1. Project-based learning

A curated list of project-based tutorials covering JavaScript, Python and many other popular languages

πŸ”— github.com/tuvtran/projec…
2. Awesome Linux software

A list of awesome applications, software, tools, and other materials for Linux distros

πŸ”— github.com/luong-komorebi…
Read 6 tweets
22 Jun
Are you planning to create your first CSS art for fun? Start with the basic shapes.

Here are 26 easy to hard shapes and figures you can try first πŸ§΅πŸ‘‡πŸ»
In general, analyze any image and try to think how can you make it using different shapes.

Two concepts that you need to master

1. border-radius
2. linear-gradient
1. Circle Yellow πŸ”΅

- Pretty simple, we just need to make a square and apply the border-radius 50% in order to give it a circular shape
Read 28 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(