Skip to content

Commit 69e9921

Browse files
Gonzalomarcylabschoolgitbook-bot
authored andcommitted
GITBOOK-23: No subject
1 parent 48f34a8 commit 69e9921

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

mod-7-react/1-intro-to-react.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ In this lesson, you will learn the basics of React.
2727

2828
* **React** — a library for building reusable, composable, and scalable user-interfaces made up of components.
2929
* **Component** — a piece of the UI (user interface) that has its own logic and appearance. Components are functions that return JSX.
30-
* **JSX** — an extension of JavaScript that lets you write HTML in React components.
30+
* **JSX** — an extension of JavaScript that lets you write HTML-like syntax in React components.
3131
* **Component Composition** — the process of combining smaller, reusable components together to create larger, more complex components
3232
* **Root Component** — the top-level component that all other components are children of. Typically called `App`.
3333
* **`react-dom/client`** — a React package that lets you render React components on the client (in the browser)
@@ -65,11 +65,11 @@ const Text = ({ message }) => {
6565
// This HTML-like syntax ^ is JSX
6666
```
6767

68-
In React, we are able to return markup language (like HTML) from functions. This is called **JSX** (JavaScript XML).
68+
In React, we are able to return HTML-like syntax from functions. This is called **JSX** (JavaScript XML), which allows us to execute JavaScript expressions (inside `{}`) and/or pass in data.  
6969

7070
### B. Component Composition is fast and easy to read
7171

72-
**Components** let you split the UI into independent, reusable pieces, and think about each piece in isolation.
72+
**Components** let you split the UI into independent, reusable pieces and think about each piece in isolation.
7373

7474
**Component Composition** is the process of combining smaller, reusable components together to create larger, more complex components
7575

@@ -138,7 +138,7 @@ cd <name of your project> && npm i
138138
npm run dev
139139
```
140140

141-
By default you will be given the familiar counter app. Take a look around! Every React project made by Vite will have this rough structure:
141+
By default, you will be given the familiar counter app. Take a look around! Every React project made by Vite will have this rough structure:
142142

143143
* `index.html` — the HTML file served to the client. It loads `src/main.jsx`.
144144
* `src/main.jsx` — the entry point of the app. It uses the `react-dom/client` package to render the **root component** `App` into the DOM.
@@ -151,31 +151,32 @@ By default you will be given the familiar counter app. Take a look around! Every
151151

152152
How does all of this actually get to the screen? Head over to the `main.jsx` file.
153153

154-
The primary purpose of this file is render the root component `App`. To do so we:
154+
The primary purpose of this file is to render the root component `App`. To do so we:
155155

156156
* Import a package called `ReactDOM`
157-
* Use the `ReactDOM.createRoot` method to create a `root` object.
158-
* Then we call `root.render` and pass in the `App` component.
157+
* Use the `createRoot` method to create a `root` object.
158+
* Then we call `createRoot(root).render()` and pass in the `App` component as the argument.
159159

160160
This is mostly handled when Vite creates the project for you so no need to memorize it:
161161

162162
```jsx
163163
// main.jsx
164-
import React from 'react'
165-
import ReactDOM from 'react-dom/client'
164+
import { StrictMode } from 'react'
165+
import { createRoot } from 'react-dom/client'
166+
import './index.css'
166167
import App from './App.jsx'
167168

168-
ReactDOM.createRoot(document.getElementById('root')).render(
169-
<React.StrictMode>
169+
createRoot(document.getElementById('root')).render(
170+
<StrictMode>
170171
<App />
171-
</React.StrictMode>,
172+
</StrictMode>,
172173
)
173174
```
174175

175176
A few notes:
176177

177178
* We're using the `client` version of `ReactDOM` (there is also a `native` version for mobile).
178-
* `React.StrictMode` is a wrapper-component that detects potential React-related in our application. It doesn't render anything visible.
179+
* `StrictMode` is a wrapper-component that detects potential React-related in our application. It doesn't render anything visible.
179180

180181
### Components and JSX
181182

@@ -197,7 +198,7 @@ const App = () => {
197198
export default App
198199
```
199200
200-
* Component are functions that return JSX.
201+
* Components are functions that return JSX.
201202
* Note the capitalized name. All components must use PascalCasing.
202203
* Components must return a single surrounding element. Here, we return a `header`.
203204
* When returning multiple elements, wrap the elements parentheses `()`.

0 commit comments

Comments
 (0)