Skip to content

Commit b10bbe8

Browse files
fix links and add ToC
1 parent 27accdb commit b10bbe8

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
55
— Facebook (the creators/maintainers of this thing)
66

7+
**Table of Contents**
8+
9+
- [What is React?](#what-is-react)
10+
- [Components](#components)
11+
- [JSX](#jsx)
12+
- [Props](#props)
13+
- [State](#state)
14+
- [Rendering](#rendering)
15+
- [Create React App](#create-react-app)
16+
- [Effects](#effects)
17+
718
---
819

920
## Assumptions
@@ -103,7 +114,7 @@ function Clock() {
103114
}
104115
```
105116
106-
(See [`clock.html`](https://davidhartsough.com/intro-to-react/examples/clock.html) and [source](https://github.com/davidhartsough/intro-to-react/examples/clock.html).)
117+
(See [`clock.html`](https://davidhartsough.com/intro-to-react/examples/clock.html) and [source](https://github.com/davidhartsough/intro-to-react/blob/master/examples/clock.html).)
107118
108119
JSX allows you to create components that mix your logic and data with your markup — tastefully. (By that I mean: better than template languages.)
109120
@@ -125,7 +136,7 @@ function App() {
125136
}
126137
```
127138
128-
(See [`random.html`](https://davidhartsough.com/intro-to-react/examples/random.html) and [source](https://github.com/davidhartsough/intro-to-react/examples/random.html).)
139+
(See [`random.html`](https://davidhartsough.com/intro-to-react/examples/random.html) and [source](https://github.com/davidhartsough/intro-to-react/blob/master/examples/random.html).)
129140
130141
This demonstrates another beauty of JSX: components become custom markup "elements", which are always denoted with capital letters. (Every component _must_ begin with a capital letter; otherwise React treats anything starting with lowercase letters as HTML DOM tags.) In this case, the RandomPhoto component is reused thrice and rendered inside the App component's element tree.
131142

@@ -146,7 +157,7 @@ function ColorList() {
146157
}
147158
```
148159

149-
(See [`color-list.html`](https://davidhartsough.com/intro-to-react/examples/color-list.html) and [source](https://github.com/davidhartsough/intro-to-react/examples/color-list.html).)
160+
(See [`color-list.html`](https://davidhartsough.com/intro-to-react/examples/color-list.html) and [source](https://github.com/davidhartsough/intro-to-react/blob/master/examples/color-list.html).)
150161

151162
Here we use a JavaScript array of strings (in the `colors` variable) to create 3 `<li>` elements and stylize the font of each with its respective color.
152163

@@ -191,7 +202,7 @@ function App() {
191202
}
192203
```
193204

194-
(See [`color-lists.html`](https://davidhartsough.com/intro-to-react/examples/color-lists.html) and [source](https://github.com/davidhartsough/intro-to-react/examples/color-lists.html).)
205+
(See [`color-lists.html`](https://davidhartsough.com/intro-to-react/examples/color-lists.html) and [source](https://github.com/davidhartsough/intro-to-react/blob/master/examples/color-lists.html).)
195206

196207
Every component is a function. Every component function recieves one parameter called props. Every props argument is an object. Every key-value pair is an individual prop. Every prop is passed to a component via HTML-attribute-like syntax in JSX.
197208

@@ -223,7 +234,7 @@ function App() {
223234
}
224235
```
225236

226-
(See [`greeting.html`](https://davidhartsough.com/intro-to-react/examples/greeting.html) and [source](https://github.com/davidhartsough/intro-to-react/examples/greeting.html).)
237+
(See [`greeting.html`](https://davidhartsough.com/intro-to-react/examples/greeting.html) and [source](https://github.com/davidhartsough/intro-to-react/blob/master/examples/greeting.html).)
227238

228239
This demonstrates the use of default props and "children" props. To set defaults for a component's props, all you have to do is set defaults for the function parameter.
229240
@@ -248,6 +259,8 @@ function Clicker() {
248259
}
249260
```
250261
262+
(See [`clicker.html`](https://davidhartsough.com/intro-to-react/examples/clicker.html) and [source](https://github.com/davidhartsough/intro-to-react/blob/master/examples/clicker.html).)
263+
251264
### Syntax
252265
253266
State is optional, so to declaratively include state, you must invoke `useState`, which you import from React. `useState` accepts one parameter, which sets the default for the state variable, and then it returns a pair (array) of values: `[1]` the current state variable and `[2]` a function that updates it. Best practices encourage you to destructure this returned array into two separate variables that should be named as a pair. The first returned value should be the name of the local variable itself (ex: `age` or `color`), but the second returned value should be named the same but with "set" as a prefix and then camelCase following (ex: `setAge` or `setColor`).
@@ -270,6 +283,8 @@ function NameForm() {
270283
}
271284
```
272285
286+
(See [`name-form.html`](https://davidhartsough.com/intro-to-react/examples/name-form.html) and [source](https://github.com/davidhartsough/intro-to-react/blob/master/examples/name-form.html).)
287+
273288
## Rendering
274289
275290
So it's about dang time I showed you how to actually render any of these components you've been making. And the good news is that it's just a dead simple one-liner call to `ReactDom.render()`.
@@ -285,7 +300,7 @@ Yep. That's it.
285300
286301
## Create React App
287302
288-
So far we've only tried things out in an HTML file with CDN imports of development JS files and then inline Babel scripts... That's not the real deal. It's just for testing in a tiny sandbox. If you actually want to create a legit, production-ready React app, use **Create React App**. See links to the GitHub,
303+
So far we've only tried things out in an HTML file with CDN imports of development JS files and then inline Babel scripts... That's not the real deal. It's just for testing in a tiny sandbox. If you actually want to create a legit, production-ready React app, use [**Create React App**](https://create-react-app.dev/) ([GitHub](https://github.com/facebook/create-react-app)).
289304
290305
Wanna try it? If you have Node >= 8.10 and npm >= 5.6 on your machine, then just run these commands in your terminal:
291306

0 commit comments

Comments
 (0)