⚡️ Day 84 ⚡️

Today

- Made a little progress on my project using react + tailwindcss.

- Studied Controlled Components in React.

Let us discuss Controlled Components.

A Thread 🧵

#100DaysOfCode
{1/12}
What are Controlled Components ?

- Let us take an example of an HTML form.

i.e

<form>
<label>
Name:
<input type="text" name="name" />
</label>
<input type="submit" value="Submit" />
</form>

In HTML, form elements naturally keep internal state.
{2/12}

For e.g -

- If you type the name in the input section and submit the button then the value of name will be submitted. so this is all controlled by HTML.

- If we do the above process using React then the process is called Controlled Component Process.
{3/12}

Advantages of Controlled Components.

- single source of truth i.e only one React is the source of control.

- We can apply the benefits of the framework to the element which is controlled.
{4/12}

Example of Controlled Component in React -

We will take the example of the above form element.

1. First we will make a class in which all-controlling action will take place.

i.e

class NameForm extends React.Component

where NameForm is a subclass of React.Component.
{5/12}

2. we have to preserve the current state and make onSubmit and onChange events so for all these we have to define the variable/function.

- we will define them inside the constructor.
{6/12}

- For example:-

constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

- super(props) means it is a subclass.

- this.state means a variable storing state.
{7/12}

-this.handleChange = this.handleChange.bind(this);

-this.handleSubmit = this.handleSubmit.bind(this);

The above are actions that we have to bind in React.
{8/12}

Let us discuss the onChange event of input.

- If the input is changing we have to store this in the current state.

This is done by "handleChange" that we have defined.

handleChange(event) {
this.setState({value: event.target.value});
}
{9/12}

In the above, if any change in the input corresponding state will be updated.

- Next, we will make the onSubmit action.

handleSubmit(event) {
event.preventDefault();
}
{10/12}

In this example, we do not want any action to take place on submitting so we use the "event.preventDefault();" method which says that no action on submitting.
{11/12}
- Now we will write the form element.

see the snippet.

--> onSubmit={this.handleSubmit} this action call to handleSubmit function.

--> value={this.state.value} this action will keep the input.

--> onChange={this.handleChange} this action will call to handleChange.
{12/12}

⭐️ complete code snippets for reference purposes.
If you like this make sure to:

Follow me @tejinder_id for web development-related tweets.

Thank you so much for staying to the end of this thread.

• • •

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

Keep Current with Tejinder Sharma

Tejinder Sharma 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 @tejinder_id

May 12
⚡️ Useful HTML and CSS tips.⚡️

A Thread 🧵 Image
1. We can use an emoji icon in our HTML and its size using font-size property. Image
2. We can style the placeholder by selecting it using ::placeholder pseudo-element. Image
Read 11 tweets
May 11
⚡️ Day 85 ⚡️

Today

- Made a little progress on my project using react + tailwindcss.

- Studied npm(Node Package Manager).

Let us basics npm.

A Thread 🧵

#100DaysOfCode
{1/4}

What is npm?

-> npm is the world's largest Software Registry.

-> Open-source developers use npm to share software.

-> npm is free to use.
{2/4}

How to install npm?

-> npm is installed with Node.js.

-> This means that you have to install Node.js to get npm installed on your computer.

-> Download Node.js from the official Node.js web site: nodejs.org
Read 6 tweets
May 11
Let us design icon links using HTML and CSS.

- We will use the main properties of CSS i.e Flex and inline-flex.

A thread 🧵 Image
1. First, we will make an HTML structure.

- We are taking 3 icons. Image
2. Next, we will make the container a flex.

-> To make the gap between icons we use justify-content: space-between.

--> Width and max-width mean the container will not be larger than max-width and if the width is less than the max-width then the container width will be 80%. Image
Read 7 tweets
May 10
⚡️ Let us discuss how to make a hover button with some fill color from top left to bottom right.

A thread 🧵
1. First we will make a basic HTML structure with "a" tag.
2. Now we will design the "a" tag in CSS.

--> position: relative because we will use ::before pseudo-element whose position is absolute.

--> We will add basis properties like padding, font size, and background colors to it.
Read 7 tweets
May 9
⚡️Day 83 ⚡️

Today -

- Continued my study with React JS.

- Made a hero section of my portfolio website.

- Studied how to use the typewriter effect in our project.

Let us discuss how to install the npm package of the typewriter effect in react.

A thread 🧵

#100DaysOfCode.
{1/6}

First, we will install the react-typing-effect npm package using the npm command.

How to install it?

Step 1:-

- First, change PWD(present working directory) to my-app or my-project folder in your VSCode editor.

- command is - cd my-app or cd my-project.
{2/6}

Step 2:- Go to google and search "react-typing-effect npm package."

- Copy the npm command i.e `npm install --save react-typing-effect`.

- Paste this command in our VS code editor terminal.

- Now it is installed.
Read 8 tweets
May 9
⚡️ Let us discuss how to make a hero image( A Hero Image is a large image with text, often placed at the top of a webpage).

A Thread 🧵 Image
1. First we will make a basic HTML structure. Image
2. We will Import google fonts and do some basic resettings. Image
Read 7 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

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(