You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/tutorials/React.md
+14-7Lines changed: 14 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,19 @@
1
1
This quick start guide will teach you how to wire up TypeScript with [React](http://facebook.github.io/react/).
2
2
By the end, you'll have
3
3
4
+
* a project with React and TypeScript
4
5
* linting with [TSLint](https://github.com/palantir/tslint)
5
-
* testing with [Jest](https://facebook.github.io/jest/), and
6
+
* testing with [Jest](https://facebook.github.io/jest/) and [Enzyme](http://airbnb.io/enzyme/), and
6
7
* state management with [Redux](https://github.com/reactjs/react-redux)
7
8
8
-
We'll use the [create-react-app](https://github.com/facebookincubator/create-react-app) tool to quickly get set up, and then eject to see how these tools are all put together.
9
+
We'll use the [create-react-app](https://github.com/facebookincubator/create-react-app) tool to quickly get set up.
9
10
10
11
We assume that you're already using [Node.js](https://nodejs.org/) with [npm](https://www.npmjs.com/).
12
+
You may also want to get a sense of [the basics with React](https://facebook.github.io/react/docs/hello-world.html).
11
13
12
14
# Install create-react-app
13
15
14
-
We're going to use the create-react-app because it sets some canonical defaults for React projects.
16
+
We're going to use the create-react-app because it sets some useful tools and canonical defaults for React projects.
15
17
This is just a command-line utility to scaffold out new React projects.
16
18
17
19
```shell
@@ -44,7 +46,7 @@ my-app/
44
46
45
47
Of note:
46
48
47
-
*`tsconfig.json` contains some TypeScript-specific options for our project.
49
+
*`tsconfig.json` contains TypeScript-specific options for our project.
48
50
*`tslint.json` stores the settings that our linter, [TSLint](https://github.com/palantir/tslint), will use.
49
51
*`package.json` contains our dependencies, as well as some shortcuts for commands we'd like to run for testing, previewing, and deploying our app.
50
52
*`public` contains static assets like the HTML page we're planning to deploy to, or images. You can delete any file in this folder apart from `index.html`.
@@ -208,7 +210,8 @@ To style our `Hello` component, we can create a CSS file at `src/components/Hell
208
210
}
209
211
```
210
212
211
-
The tools that create-react-app uses (namely, Webpack and various loaders) allow us to import the stylesheets we're interested in.
213
+
The tools that create-react-app uses (namely, Webpack and various loaders) allow us to just import the stylesheets we're interested in.
214
+
When our build runs, any imported `.css` files will be concatenated into an output file.
212
215
So in `src/components/Hello.tsx`, we'll add the following import.
213
216
214
217
```ts
@@ -295,7 +298,7 @@ On its own, React is a useful library for creating composable views.
295
298
However, React doesn't come with any facility for synchronizing data between your application.
296
299
As far as a React component is concerned, data flows down through its children through the props you specify on each element.
297
300
298
-
As an answer, the React community relies on libraries like Redux and MobX.
301
+
Because React on its own does not provide a built-in support for state management, the React community uses libraries like Redux and MobX.
299
302
300
303
[Redux](http://redux.js.org) relies on synchronizing data through a centralized and immutable store of data, and updates to that data will trigger a re-render our application.
301
304
State is updated in an immutable fashion by sending explicit action messages which must be handled by functions called reducers.
@@ -305,10 +308,13 @@ Because of the explicit nature, it is often be easier to reason about how an act
305
308
Keeping state fully synchronized for any observers is done by simply marking state as observable.
306
309
As a nice bonus, the library is already written in TypeScript.
307
310
308
-
There are various merits and have tradeoffs to both.
311
+
There are various merits and tradeoffs to both.
309
312
Generally Redux tends to see more widespread usage, so for the purposes of this tutorial, we'll focus on adding Redux;
310
313
however, you should feel encouraged to explore both.
311
314
315
+
The following section may have a steep learning curve.
316
+
We strongly suggest you [familiarize yourself with Redux through its documentation](http://redux.js.org/).
317
+
312
318
## Setting the stage for actions
313
319
314
320
It doesn't make sense to add Redux unless the state of our application changes.
@@ -615,6 +621,7 @@ npm run eject
615
621
and you should be good to go!
616
622
617
623
As a heads up, you may want to commit all your work before running an eject.
624
+
You cannot undo an eject command, so opting out is permanent without committing.
0 commit comments