Fixed Typographical Error in guide/english/react/index.md (#35187)

* Update index.md

* Update index.md
This commit is contained in:
Rajiv Ranjan Singh
2019-02-14 09:18:33 +05:30
committed by Christopher McCormack
parent e360c8d627
commit af75d47594

View File

@ -45,8 +45,8 @@ ReactDOM.render(
); );
``` ```
2. React is declarative. For the most part, we are concerned more with *What to do* rather than *How to do* a specific task. Declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow. 2. React is declarative, which means you are concerned more with **what** to do rather than **how** to do a specific task. Declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow.
Declarative programming comes with advantages, such as reduced side effects (occurs when we modify any state, mutating something or making an API request), minimizing mutability (mostly abstracted), enhanced readability and less bugs. Declarative programming comes with certain advantages such as reduced side effects that occur when you modify any state, mutate something, or make an API request. Other advantages are minimizing mutability (mostly abstracted), enhanced readability, and fewer bugs.
3. Unidirectional dataflow. UI in React is actually the function of the state, which means that as the state updates, it updates the UI as well. So our UI progresses as the state changes. 3. Unidirectional dataflow. UI in React is actually the function of the state, which means that as the state updates, it updates the UI as well. So our UI progresses as the state changes.
@ -78,7 +78,7 @@ React will then instruct the browser to update only the computed diff and not th
Would you like to get started learning the basics of React without getting bogged down creating a development environment? Would you like to get started learning the basics of React without getting bogged down creating a development environment?
Chances are that if you are new to web development, just setting up a development environment can leave you feeling a little intimidated. Chances are that if you are new to web development, just setting up a development environment can leave you feeling a little intimidated.
In this article we are going to look at how we can get started with React using only a text editor and a browser and nothing else. In this article, you will start learning React using only a text editor and a browser.
<a href="http://www.youtube.com/watch?feature=player_embedded&v=100pKUE3OPI" target="_blank"> <a href="http://www.youtube.com/watch?feature=player_embedded&v=100pKUE3OPI" target="_blank">
<img src="https://img.youtube.com/vi/100pKUE3OPI/0.jpg" alt="Watch Video Here" width="240" height="180" border="10" /> <img src="https://img.youtube.com/vi/100pKUE3OPI/0.jpg" alt="Watch Video Here" width="240" height="180" border="10" />
@ -86,7 +86,7 @@ In this article we are going to look at how we can get started with React using
### 1Set Up Boiler Plate Code with Emmet ### 1Set Up Boiler Plate Code with Emmet
Lets get started with step 1. Well begin with a file in our browser called “index.html”. Well begin with the boiler plate HTML code. For a quick start I recommend using Emmet with whatever text editor you have, and on the first line typing in `html:5` then pressing the shift key to get the code below. Or you can go ahead and copy and paste the code from below. Lets get started with step 1. Youll begin with a file in our browser called “index.html”. Youll begin with the boilerplate HTML code. For a quick start I recommend using Emmet with whatever text editor you have, and on the first line typing in `html:5` then pressing the shift key to get the code below. Or you can go ahead and copy and paste the code from below.
```javascript ```javascript
html:5 html:5
@ -109,14 +109,14 @@ This will result in the following code:
</html> </html>
``` ```
We can fill in the title as “Time to React!”. You can fill in the title as “Time to React!”.
This content will not appear in your webpage. Anything in the head section of the HTML file will be metadata that our browser will user to interpret our code in the body section. This title is going to be what appears on the tab for our page, not actually on the page. This content will not appear on your webpage. Anything in the head section of the HTML file will be metadata that our browser will use to interpret the code in the body section. This title is going to be what appears on the tab for your page, not actually on the page.
### 2 - Get Script Tags to Harness the Power of React and Babel Libraries ### 2 - Get Script Tags to Harness the Power of React and Babel Libraries
Ok, item one is checked off our list. Lets look at item two. We are going to set up our developer environment by using script tags to bring in React and Babel. This is not a real life developer environment. That would be quite an elaborate setup. It would also leave us with a lot of boiler plate code and libraries that would take us off subject of learning React basics. The goal of this series is to go over the basic syntax of React and get right into coding. Ok, item one is checked off your list. Lets look at item two. You are going to set up our developer environment by using script tags to bring in React and Babel. This is not a real-life developer environment. That would be quite an elaborate setup. It would also leave us with a lot of boilerplate code and libraries that would take us off the subject of learning React basics. The goal of this series is to go over the basic syntax of React and get right into coding.
We are going to use `<script>` tags to bring in the React library, the React DOM library, and the Babel library. You are going to use `<script>` tags to bring in the React library, the React DOM library, and the Babel library.
```javascript ```javascript
<head> <head>
@ -132,22 +132,22 @@ We are going to use `<script>` tags to bring in the React library, the React DOM
</head> </head>
``` ```
You are free to use more updated versions of these libraries as they come out. They should not create any breaking changes for the content we are covering. You are free to use more updated versions of these libraries as they come out. They should not create any breaking changes for the content you are covering.
What are we doing here? What are we doing here?
The: HTML `<script>` element is used to embed or reference an executable script. The “src” attribute points to the external script files for the React library, ReactDOM library and Babel library. The: HTML `<script>` element is used to embed or reference an executable script. The “src” attribute points to the external script files for the React library, ReactDOM library and Babel library.
This is like if you have an electric razor. It is literally no good to you no matter how fancy the electric razor unless you can plug it into the wall and gain access to electricity. Our React code we will write will be no good to us if our browser cant plug into these libraries to understand and interpret what we are going. This is like if you have an electric razor. It is literally no good to you no matter how fancy the electric razor unless you can plug it into the wall and gain access to electricity. Your React code we will write will be no good to us if your browser cant plug into these libraries to understand and interpret what you are going.
This is how our application is going to gain the power of React, it is going to be how we insert React into the DOM. The reason that we have React and ReactDOM as two different libraries is because there are use cases such as React Native where rendering to the DOM isnt needed for mobile development so the library was split for people to make the decision for what they need depending on the project they are working on. Because we will need our React to make it to the DOM well use both scripts. This is how your application is going to gain the power of React, it is going to be how you insert React into the DOM. The reason that you have React and ReactDOM as two different libraries is because there are use cases such as React Native where rendering to the DOM isnt needed for mobile development so the library was split for people to make the decision for what they need depending on the project they are working on. Because you will need your React to make it to the DOM youll use both scripts.
Babel is how we take advantage of new versions of JavaScript beyond ES5 and deal with something called JSX (JavaScript as XML) that we will use in React. Well take a deeper look at the magic of Babel in an upcoming lesson :) Babel is how we take advantage of new versions of JavaScript beyond ES5 and deal with something called JSX (JavaScript as XML) that you will use in React. Youll take a deeper look at the magic of Babel in an upcoming lesson :)
Alright, we have completed steps 1 and 2. We have set up our boiler plate code and set up our developer environment. Alright, we have completed steps 1 and 2. We have set up your boilerplate code and set up your developer environment.
### 3 - Render React to the DOM ### 3 - Render React to the DOM
Our next two steps will be to choose our location within DOM that we want to render our React content and use another script tag for our React content within the body. Generally, as a good separation of concerns practice, this would be in its own file then linked to this HTML document. Well do that later in upcoming lessons. Your next two steps will be to choose your location within DOM that you want to render your React content and use another script tag for your React content within the body. Generally, as good separation of concerns practice, this would be in its own file then linked to this HTML document. Youll do that later in upcoming lessons.
For now, well let this live within the body of the HTML document. For now, youll let this live within the body of the HTML document.
Now we are going to look at how simple it is to choose a place on the DOM to render our React content. Now you are going to look at how simple it is to choose a place on the DOM to render your React content.
Well go within the body. Best practice isnt just to throw React into the body tag to be displayed, but to create a separate element, often a `<div>`, that you can treat as a root element to insert your React content. Youll go within the body. Best practice isnt just to throw React into the body tag to be displayed, but to create a separate element, often a `<div>`, that you can treat as a root element to insert your React content.
```javascript ```javascript
<body> <body>
@ -155,9 +155,9 @@ Well go within the body. Best practice isnt just to throw React into the b
</body> </body>
``` ```
Well create a simple `<div>` element and give it an id of “app”. We are going to be able to target this location to insert our React content much the same way you might use CSS to target an id for styling of your choice. Youll create a simple `<div>` element and give it an id of “app”. You are going to be able to target this location to insert your React content much the same way you might use CSS to target id for styling of your choice.
Any React content will be rendered within the `<div>` tags with the id of app. In the meantime well leave some text saying that “React has not rendered yet”. If we see this when we preview our page, it means that somewhere we missed rendering React. Any React content will be rendered within the `<div>` tags with the id of the app. In the meantime, youll leave some text saying that “React has not rendered yet”. If you see this when you preview your page, it means that somewhere you missed rendering React.
Now, lets go ahead and create a script tag within our body where we will create with react for the first time. The syntax we are going to need for our script tag is to add an attribute of “type”. This specifies the media type of the script. Above in our head we used an src attribute that pointed to the external script files for the React library, ReactDOM library and Babel library. Now, lets go ahead and create a script tag within your body where you will create with react for the first time. The syntax you are going to need for your script tag is to add an attribute of “type”. This specifies the media type of the script. Above in your head, you used an src attribute that pointed to the external script files for the React library, ReactDOM library and Babel library.
```javascript ```javascript
<body> <body>
@ -167,8 +167,8 @@ Now, lets go ahead and create a script tag within our body where we will crea
</body> </body>
``` ```
The “type” of script that we are using is wrapped in quotes and set it to `"text/babel"`. The “type” of the script that you are using is wrapped in quotes and set it to `"text/babel"`.
Well need this ability to use Babel right away as we work with JSX. First, we are going to render React to the DOM. We will use the `ReactDOM.render()` method to do this. This will be a method, and remember a method is just a function attached to an object. This method will take two arguments. Youll need this ability to use Babel right away as you work with JSX. First, you are going to render React to the DOM. You will use the `ReactDOM.render()` method to do this. This will be a method, and remember a method is just a function attached to an object. This method will take two arguments.
```javascript ```javascript
<body> <body>
@ -182,7 +182,7 @@ Well need this ability to use Babel right away as we work with JSX. First, we
The first argument is the “what” of React. The second argument is the “where” of the location you want it to be placed in the DOM. The first argument is the “what” of React. The second argument is the “where” of the location you want it to be placed in the DOM.
Lets start by calling our ReactDOM.render() method. Lets start by calling our ReactDOM.render() method.
Our first argument is going to be our JSX. Your first argument is going to be your JSX code.
```javascript ```javascript
<body> <body>
@ -196,14 +196,14 @@ Our first argument is going to be our JSX.
</body> </body>
``` ```
The [official React docs state](https://reactjs.org/docs/introducing-jsx.html): “This funny tag syntax is neither a string nor HTML. It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI should look like. JSX may remind you of a template language, but it comes with the full power of JavaScript. JSX produces React “elements”.” The [official React docs state](https://reactjs.org/docs/introducing-jsx.html): “This funny tag syntax is neither a string nor HTML. It is called JSX, and it is a syntax extension to JavaScript. You recommend using it with React to describe what the UI should look like. JSX may remind you of a template language, but it comes with the full power of JavaScript. JSX produces React “elements”.”
Often times, JSX freaks out people who have been developers for a while because it looks like HTML. Developers have traditionally been taught early on about separation of concerns. HTML has its place, CSS has its place and JavaScript has its place. JSX seems to blur the lines. You are using what looks like HTML but as React says, has the full power of JavaScript. Often times, JSX freaks out people who have been developers for a while because it looks like HTML. Developers have traditionally been taught early on about separation of concerns. HTML has its place, CSS has its place and JavaScript has its place. JSX seems to blur the lines. You are using what looks like HTML but as React says, has the full power of JavaScript.
This can alarm some people, so many React tutorials start without JSX, which can complicate getting started. We wont do that. Because this course is directed towards those who are very early in their careers, you may not be as alarmed by the syntax. This can alarm some people, so many React tutorials start without JSX, which can complicate getting started. You wont do that. Because this course is directed towards those who are very early in their careers, you may not be as alarmed by the syntax.
And JSX is just really intuitive. You can probably quite easily read this code and see that this is going to be the largest header tag displaying the text “Hello World”: no mystery and pretty straightforward. And JSX is just really intuitive. You can probably quite easily read this code and see that this is going to be the largest header tag displaying the text “Hello World”: no mystery and pretty straightforward.
Now, lets look at what our second argument would be. Now, lets look at what your second argument would be.
```javascript ```javascript
<body> <body>
@ -217,13 +217,13 @@ Now, lets look at what our second argument would be.
</body> </body>
``` ```
This is where we want our React content rendered to the DOM. Youve probably done this quite a few times in the past. Well just type in `document.getElementById()`. And well pass into the argument of the id of app. And that is it. We will now target the `<div>` with the id of app to insert our react content. This is where you want your React content rendered to the DOM. Youve probably done this quite a few times in the past. Youll just type in `document.getElementById()`. And youll pass into the argument of the id of the app. And that is it. You will now target the `<div>` with the id of the app to insert our react to content.
We want to make sure our content is saved. Go ahead and open this up in your browser, and you should see “Hello World”. As you can probably guess, using React is not the quickest or best way to create a Hello World app. We arent quite seeing the benefits of it yet. But now, we know that everything is working. You want to make sure your content is saved. Go ahead and open this up in your browser, and you should see “Hello World”. As you can probably guess, using React is not the quickest or best way to create a Hello World app. You arent quite seeing the benefits of it yet. But now, you know that everything is working.
Go ahead and open up the console and look at the “Elements” tab. You can do that on a mac with command + shift + j or on a On Windows and Linux: Ctrl + Shift + J Go ahead and open up the console and look at the “Elements” tab. You can do that on a mac with command + shift + j or on an On Windows and Linux: Ctrl + Shift + J
If you click on the head tag your can see the script libraries we included. Then we can go down to body of our document. Lets click on our div with the id of `app`, and see our `<h1>` tag with the content “Hello World”. If you click on the head tag you can see the script libraries we included. Then you can go down to the body of our document. Lets click on your div with the id of `app`, and see our `<h1>` tag with the content “Hello World”.
[View Entire Code Here](https://github.com/robgmerrill/hello-react/blob/master/section-one/index.html) [View Entire Code Here](https://github.com/robgmerrill/hello-react/blob/master/section-one/index.html)
@ -233,14 +233,14 @@ or
alt="Watch Video Here" width="240" height="180" border="10" /></a> alt="Watch Video Here" width="240" height="180" border="10" /></a>
### Quick React App Setup ### Quick React App Setup
Setting up a react app can be time consuming. A great tool for starting a new react project is create-react-app. Setting up a react app can be time-consuming. A great tool for starting a new react project is create-react-app.
Get more information about it [here](https://github.com/facebook/create-react-app#readme) Get more information about it [here](https://github.com/facebook/create-react-app#readme)
### Recap ### Recap
So lets do a quick recap. In our head tag we grabbed the script tags for React, ReactDOM and Babel. These are the tools our browser needs in its metadata to read our React code. So lets do a quick recap. In your head tag you grabbed the script tags for React, ReactDOM and Babel. These are the tools your browser needs in its metadata to read your React code.
We then located the position within the DOM that we wanted to insert our React by creating an element `<div>` with the id of “app”. You then located the position within the DOM that you wanted to insert your React by creating an element `<div>` with the id of “app”.
Next, we created a script tag to input our React code. We used the ReactDOM.render() method that takes two arguments. The “what” of the React content, in this case our JSX, and the second argument is the “where” that you want to insert the React content into the DOM. In this case it is the location with the id of “app”. Next, you created a script tag to input your React code. You used ReactDOM.render() method that takes two arguments. The “what” of the React content, in this case your JSX, and the second argument is the “where” that you want to insert the React content into the DOM. In this case it is the location with the id of “app”.
As an alternative to JSX, you can use ES6 and Javascript's compiler like Babel. [https://babeljs.io/](https://babeljs.io/) As an alternative to JSX, you can use ES6 and Javascript's compiler like Babel. [https://babeljs.io/](https://babeljs.io/)