Skip to content

Commit 6c53f6b

Browse files
committed
refactor: reverted all formatting and just just mention src folder in introductory section
1 parent 8657e86 commit 6c53f6b

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/content/learn/tutorial-tic-tac-toe.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -283,27 +283,27 @@ In CodeSandbox you'll see three main sections:
283283

284284
![CodeSandbox with starter code](../images/tutorial/react-starter-code-codesandbox.png)
285285

286-
1. In the *Files* section, you’ll see files like `src/App.js`, `src/index.js`, `src/styles.css`, and a `public` folder.
287-
1. The *code editor* where you'll see the source code of your selected file
288-
1. The *browser* section where you'll see how the code you've written will be displayed
286+
1. The _Files_ section with a list of files like `App.js`, `index.js`, `styles.css` in `src` folder and a folder called `public`
287+
1. The _code editor_ where you'll see the source code of your selected file
288+
1. The _browser_ section where you'll see how the code you've written will be displayed
289289

290-
The `src/App.js` file should be selected in the *Files* section. The contents of that file in the *code editor* should be:
290+
The `App.js` file should be selected in the _Files_ section. The contents of that file in the _code editor_ should be:
291291

292292
```jsx
293293
export default function Square() {
294294
return <button className="square">X</button>;
295295
}
296296
```
297297

298-
The *browser* section should be displaying a square with an X in it like this:
298+
The _browser_ section should be displaying a square with an X in it like this:
299299

300300
![x-filled square](../images/tutorial/x-filled-square.png)
301301

302302
Now let's have a look at the files in the starter code.
303303

304-
#### `src/App.js` {/*appjs*/}
304+
#### `App.js` {/*appjs*/}
305305

306-
The code in `src/App.js` creates a *component*. In React, a component is a piece of reusable code that represents a part of a user interface. Components are used to render, manage, and update the UI elements in your application. Let's look at the component line by line to see what's going on:
306+
The code in `App.js` creates a _component_. In React, a component is a piece of reusable code that represents a part of a user interface. Components are used to render, manage, and update the UI elements in your application. Let's look at the component line by line to see what's going on:
307307

308308
```js {1}
309309
export default function Square() {
@@ -321,13 +321,13 @@ export default function Square() {
321321

322322
The second line returns a button. The `return` JavaScript keyword means whatever comes after is returned as a value to the caller of the function. `<button>` is a *JSX element*. A JSX element is a combination of JavaScript code and HTML tags that describes what you'd like to display. `className="square"` is a button property or *prop* that tells CSS how to style the button. `X` is the text displayed inside of the button and `</button>` closes the JSX element to indicate that any following content shouldn't be placed inside the button.
323323

324-
#### `src/styles.css` {/*stylescss*/}
324+
#### `styles.css` {/*stylescss*/}
325325

326-
Click on the file labeled `src/styles.css` in the *Files* section of CodeSandbox. This file defines the styles for your React app. The first two *CSS selectors* (`*` and `body`) define the style of large parts of your app while the `.square` selector defines the style of any component where the `className` property is set to `square`. In your code, that would match the button from your Square component in the `src/App.js` file.
326+
Click on the file labeled `styles.css` in the _Files_ section of CodeSandbox. This file defines the styles for your React app. The first two _CSS selectors_ (`*` and `body`) define the style of large parts of your app while the `.square` selector defines the style of any component where the `className` property is set to `square`. In your code, that would match the button from your Square component in the `App.js` file.
327327

328-
#### `src/index.js` {/*indexjs*/}
328+
#### `index.js` {/*indexjs*/}
329329

330-
Click on the file labeled `src/index.js` in the *Files* section of CodeSandbox. You won't be editing this file during the tutorial but it is the bridge between the component you created in the `src/App.js` file and the web browser.
330+
Click on the file labeled `index.js` in the _Files_ section of CodeSandbox. You won't be editing this file during the tutorial but it is the bridge between the component you created in the `App.js` file and the web browser.
331331

332332
```jsx
333333
import { StrictMode } from 'react';
@@ -337,18 +337,18 @@ import './styles.css';
337337
import App from './App';
338338
```
339339

340-
Lines 1-5 bring all the necessary pieces together:
340+
Lines 1-5 bring all the necessary pieces together:
341341

342-
- React
343-
- React's library to talk to web browsers (React DOM)
344-
- the styles for your components
345-
- the component you created in `src/App.js`.
342+
* React
343+
* React's library to talk to web browsers (React DOM)
344+
* the styles for your components
345+
* the component you created in `App.js`.
346346

347347
The remainder of the file brings all the pieces together and injects the final product into `index.html` in the `public` folder.
348348

349349
### Building the board {/*building-the-board*/}
350350

351-
Let's get back to `src/App.js`. This is where you'll spend the rest of the tutorial.
351+
Let's get back to `App.js`. This is where you'll spend the rest of the tutorial.
352352

353353
Currently the board is only a single square, but you need nine! If you just try and copy paste your square to make two squares like this:
354354

@@ -389,7 +389,7 @@ Great! Now you just need to copy-paste a few times to add nine squares and...
389389

390390
Oh no! The squares are all in a single line, not in a grid like you need for our board. To fix this you'll need to group your squares into rows with `div`s and add some CSS classes. While you're at it, you'll give each square a number to make sure you know where each square is displayed.
391391

392-
In the `src/App.js` file, update the `Square` component to look like this:
392+
In the `App.js` file, update the `Square` component to look like this:
393393

394394
```js {3-19}
395395
export default function Square() {
@@ -415,7 +415,7 @@ export default function Square() {
415415
}
416416
```
417417

418-
The CSS defined in `src/styles.css` styles the divs with the `className` of `board-row`. Now that you've grouped your components into rows with the styled `div`s you have your tic-tac-toe board:
418+
The CSS defined in `styles.css` styles the divs with the `className` of `board-row`. Now that you've grouped your components into rows with the styled `div`s you have your tic-tac-toe board:
419419

420420
![tic-tac-toe board filled with numbers 1 through 9](../images/tutorial/number-filled-board.png)
421421

@@ -551,7 +551,7 @@ export default function Board() {
551551
}
552552
```
553553

554-
Note how unlike the browser `div`s, your own components `Board` and `Square` must start with a capital letter.
554+
Note how unlike the browser `div`s, your own components `Board` and `Square` must start with a capital letter.
555555

556556
Let's take a look:
557557

@@ -723,7 +723,7 @@ function Square({ value }) {
723723
}
724724
```
725725

726-
If you click on a square now, you should see a log saying `"clicked!"` in the *Console* tab at the bottom of the *Browser* section in CodeSandbox. Clicking the square more than once will log `"clicked!"` again. Repeated console logs with the same message will not create more lines in the console. Instead, you will see an incrementing counter next to your first `"clicked!"` log.
726+
If you click on a square now, you should see a log saying `"clicked!"` in the _Console_ tab at the bottom of the _Browser_ section in CodeSandbox. Clicking the square more than once will log `"clicked!"` again. Repeated console logs with the same message will not create more lines in the console. Instead, you will see an incrementing counter next to your first `"clicked!"` log.
727727

728728
<Note>
729729

@@ -899,7 +899,7 @@ body {
899899
900900
### React Developer Tools {/*react-developer-tools*/}
901901
902-
React DevTools let you check the props and the state of your React components. You can find the React DevTools tab at the bottom of the *browser* section in CodeSandbox:
902+
React DevTools let you check the props and the state of your React components. You can find the React DevTools tab at the bottom of the _browser_ section in CodeSandbox:
903903
904904
![React DevTools in CodeSandbox](../images/tutorial/codesandbox-devtools.png)
905905
@@ -1094,7 +1094,7 @@ function Square({ value, onSquareClick }) {
10941094
}
10951095
```
10961096
1097-
Now you'll connect the `onSquareClick` prop to a function in the `Board` component that you'll name `handleClick`. To connect `onSquareClick` to `handleClick` you'll pass a function to the `onSquareClick` prop of the first `Square` component:
1097+
Now you'll connect the `onSquareClick` prop to a function in the `Board` component that you'll name `handleClick`. To connect `onSquareClick` to `handleClick` you'll pass a function to the `onSquareClick` prop of the first `Square` component:
10981098
10991099
```js {7}
11001100
export default function Board() {
@@ -1337,7 +1337,7 @@ The DOM `<button>` element's `onClick` attribute has a special meaning to React
13371337
13381338
Note how in `handleClick`, you call `.slice()` to create a copy of the `squares` array instead of modifying the existing array. To explain why, we need to discuss immutability and why immutability is important to learn.
13391339
1340-
There are generally two approaches to changing data. The first approach is to *mutate* the data by directly changing the data's values. The second approach is to replace the data with a new copy which has the desired changes. Here is what it would look like if you mutated the `squares` array:
1340+
There are generally two approaches to changing data. The first approach is to _mutate_ the data by directly changing the data's values. The second approach is to replace the data with a new copy which has the desired changes. Here is what it would look like if you mutated the `squares` array:
13411341
13421342
```jsx
13431343
const squares = [null, null, null, null, null, null, null, null, null];
@@ -1590,7 +1590,7 @@ export default function Board() {
15901590
}
15911591
```
15921592
1593-
Congratulations! You now have a working tic-tac-toe game. And you've just learned the basics of React too. So *you* are the real winner here. Here is what the code should look like:
1593+
Congratulations! You now have a working tic-tac-toe game. And you've just learned the basics of React too. So _you_ are the real winner here. Here is what the code should look like:
15941594
15951595
<Sandpack>
15961596
@@ -1772,7 +1772,7 @@ export default function Game() {
17721772
}
17731773
```
17741774
1775-
Note that you are removing the `export default` keywords before the `function Board() {` declaration and adding them before the `function Game() {` declaration. This tells your `src/index.js` file to use the `Game` component as the top-level component instead of your `Board` component. The additional `div`s returned by the `Game` component are making room for the game information you'll add to the board later.
1775+
Note that you are removing the `export default` keywords before the `function Board() {` declaration and adding them before the `function Game() {` declaration. This tells your `index.js` file to use the `Game` component as the top-level component instead of your `Board` component. The additional `div`s returned by the `Game` component are making room for the game information you'll add to the board later.
17761776
17771777
Add some state to the `Game` component to track which player is next and the history of moves:
17781778
@@ -2073,7 +2073,7 @@ export default function Game() {
20732073
}
20742074
```
20752075
2076-
You can see what your code should look like below. Note that you should see an error in the developer tools console that says:
2076+
You can see what your code should look like below. Note that you should see an error in the developer tools console that says:
20772077
20782078
<ConsoleBlock level="warning">
20792079
Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of &#96;Game&#96;.
@@ -2272,7 +2272,7 @@ to
22722272
<li>Alexa: 5 tasks left</li>
22732273
```
22742274
2275-
In addition to the updated counts, a human reading this would probably say that you swapped Alexa and Ben's ordering and inserted Claudia between Alexa and Ben. However, React is a computer program and does not know what you intended, so you need to specify a *key* property for each list item to differentiate each list item from its siblings. If your data was from a database, Alexa, Ben, and Claudia's database IDs could be used as keys.
2275+
In addition to the updated counts, a human reading this would probably say that you swapped Alexa and Ben's ordering and inserted Claudia between Alexa and Ben. However, React is a computer program and does not know what you intended, so you need to specify a _key_ property for each list item to differentiate each list item from its siblings. If your data was from a database, Alexa, Ben, and Claudia's database IDs could be used as keys.
22762276
22772277
```js {1}
22782278
<li key={user.id}>
@@ -2915,4 +2915,4 @@ If you have extra time or want to practice your new React skills, here are some
29152915
1. When someone wins, highlight the three squares that caused the win (and when no one wins, display a message about the result being a draw).
29162916
1. Display the location for each move in the format (row, col) in the move history list.
29172917
2918-
Throughout this tutorial, you've touched on React concepts including elements, components, props, and state. Now that you've seen how these concepts work when building a game, check out [Thinking in React](/learn/thinking-in-react) to see how the same React concepts work when building an app's UI.
2918+
Throughout this tutorial, you've touched on React concepts including elements, components, props, and state. Now that you've seen how these concepts work when building a game, check out [Thinking in React](/learn/thinking-in-react) to see how the same React concepts work when building an app's UI.

0 commit comments

Comments
 (0)