Skip to content

Commit fc2f47e

Browse files
committed
Welcome!
0 parents  commit fc2f47e

File tree

150 files changed

+29594
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+29594
-0
lines changed

.firebaserc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "eight-k"
4+
}
5+
}

.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
public/flex.jpg

README.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Welcome to React Training!
2+
3+
This repo contains the course material for [React Training](https://reacttraining.com/). Before attending the training, please make sure you can run this repository.
4+
5+
## Install
6+
7+
First, install [git](http://git-scm.com/downloads) and the latest stable version of [node](https://nodejs.org/). Then:
8+
9+
```sh
10+
$ git clone https://github.com/ReactTraining/hooks-workshop.git
11+
$ cd hooks-workshop
12+
$ npm install
13+
$ npm start
14+
```
15+
16+
You'll be prompted with the exercise you'd like to run, hit "0" to view the full app we'll be working in, then, open a web browser to [http://localhost:300](http://localhost:3000).
17+
18+
```
19+
$ npm start
20+
21+
> [email protected] start ../hooks-workshop
22+
> node scripts/start.js
23+
24+
Which exercise?
25+
26+
[1] 01-rendering
27+
[2] 02-state
28+
[3] 03-controlled-components
29+
[4] 04-effects
30+
[5] 05-data-loading
31+
[6] 06-data-flow
32+
[7] 07-compound-components
33+
[8] 08-app-state
34+
[9] 09-flicker
35+
[a] 10-the-feed
36+
[b] 11-animation
37+
[c] 12-optimization
38+
[0] THE FULL APP!
39+
40+
Choose one from list [1...9, a, b, c, 0]:
41+
```
42+
43+
## Updating
44+
45+
If you've already cloned the repo but you need to get updated code, then follow these steps:
46+
47+
- First, `cd` into the root directory of the repo
48+
- Then do an `ls` command to ensure you see a `package.json` file listed. If you don't you're not in the root folder of the repo
49+
- Clear out any dirty files in your git working tree (`git stash` is a safe way to do it, `git reset ---hard` is how to live dangerously)
50+
- Then run these steps to get the updates:
51+
52+
```sh
53+
git pull origin master
54+
npm install
55+
```
56+
57+
Then you should be able to do your `npm start` again.
58+
59+
## Be Prepared
60+
61+
**IMPORTANT:** Please read our [JavaScript Primer](https://reacttraining.com/blog/javascript-the-react-parts/) before attending the workshop. It's a refresher on some of the newer bits of JavaScript you'll want to be familiar with in order to get the most out of the experience.
62+
63+
### Windows Machine?
64+
65+
We'll be running commands like the ones from the install/update instructions above. These are _bash_ commands which means if you're on Windows you'll need a bash-enabled command-line tool. If you've installed [Git For Windows](https://gitforwindows.org) then you'll have a command-line tool called Git Bash already. This seems to work out well for doing other bash things that aren't just git specific (like npm).
66+
67+
## Troubleshooting
68+
69+
A few common problems:
70+
71+
- **You're having problems cloning the repository.** Some corporate networks block port 22, which git uses to communicate with GitHub over SSH. Instead of using SSH, clone the repo over HTTPS. Use the following command to tell git to always use `https` instead of `git`:
72+
73+
```sh
74+
$ git config --global url."https://".insteadOf git://
75+
76+
# This adds the following to your `~/.gitconfig`:
77+
[url "https://"]
78+
insteadOf = git://
79+
```
80+
81+
- **You're having trouble installing node.** We recommend using [nvm](https://github.com/creationix/nvm). nvm makes it really easy to use multiple versions of node on the same machine painlessly. After you install nvm, install the latest stable version of node with the following command:
82+
83+
```sh
84+
$ nvm use default stable
85+
```
86+
87+
- **You don't have permissions to install stuff.** You might see an error like `EACCES` during the `npm install` step. If that's the case, it probably means that at some point you did an `sudo npm install` and installed some stuff with root permissions. To fix this, you need to forcefully remove all files that npm caches on your machine and re-install without sudo.
88+
89+
```sh
90+
$ sudo rm -rf node_modules
91+
92+
# If you installed node with nvm (suggested):
93+
$ sudo rm -rf ~/.npm
94+
95+
# If you installed node with Homebrew:
96+
$ sudo rm -rf /usr/local/lib/node_modules
97+
98+
# Then (look ma, no sudo!):
99+
$ npm install
100+
```
101+
102+
## License
103+
104+
This material is available for private, non-commercial use under the [GPL version 3](http://www.gnu.org/licenses/gpl-3.0-standalone.html). If you would like to use this material to conduct your own workshop, please contact us at [[email protected]](mailto:[email protected]).

Syllabus.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# React Hooks Workshop
2+
3+
## The Lessons
4+
5+
Day 1
6+
7+
- Rendering and Components
8+
- State
9+
- Controlled Components
10+
- Effects
11+
- Data Loading/subscriptions, custom hooks
12+
- Data flow, custom events
13+
14+
Day 2
15+
16+
- Compound Components (Tabs, DateFields)
17+
- useReducer and Context for App Data (useContext)
18+
- Avoiding flicker (useStateWithCache, useAppState)
19+
- Bringing it all together with pagination on the Feed page (do all local state, cause you don't want to render 3 and then reorder--gross!)
20+
- Animation (useCallback on AnimatedText, useTween, AnimatedDialog, coin)
21+
- Optimizations
22+
- Review
23+
24+
## Workshop Objectives
25+
26+
After completing, attendees will:
27+
28+
- Have an advanced understanding of building UI with React
29+
30+
- Composing UI elements
31+
- Composing State
32+
- Composing Behaviors (side-effects)
33+
34+
- Be able to put together an entire application with
35+
36+
- Data loading
37+
- Routing
38+
- Authentication
39+
40+
- Be able to build a data loading strategy
41+
42+
- Fetch
43+
- Realtime
44+
- caching
45+
- pagination
46+
47+
- Be able to build advanced interactions with
48+
49+
- Animation
50+
- Keyboard support
51+
- Assistive Tech (screen reader) Support
52+
53+
- Be able to manage side-effects
54+
55+
- Document title
56+
- Session Storage
57+
- Web audio

anatomy.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
The anatomy of a React Application:
2+
3+
1. User Interface
4+
2. Events
5+
3. State
6+
- Persistent
7+
- Implicit
8+
- Explicit
9+
4. Effects
10+
5. Optimizations
11+
12+
Primitives:
13+
14+
1. User Interface
15+
16+
- Rendering Targets (ReactDOM)
17+
- Elements and Components
18+
- useRef
19+
20+
2. Events
21+
22+
- built-in
23+
- custom
24+
25+
3. State
26+
27+
- useState
28+
- useReducer
29+
- props
30+
- cloneElement
31+
- context
32+
33+
4. Effects
34+
35+
- useEffect
36+
37+
5. Optimizations
38+
- memo
39+
- useMemo
40+
- useCallback

config/env.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const paths = require('./paths');
6+
7+
// Make sure that including paths.js after env.js will read .env variables.
8+
delete require.cache[require.resolve('./paths')];
9+
10+
const NODE_ENV = process.env.NODE_ENV;
11+
if (!NODE_ENV) {
12+
throw new Error(
13+
'The NODE_ENV environment variable is required but was not specified.'
14+
);
15+
}
16+
17+
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
18+
var dotenvFiles = [
19+
`${paths.dotenv}.${NODE_ENV}.local`,
20+
`${paths.dotenv}.${NODE_ENV}`,
21+
// Don't include `.env.local` for `test` environment
22+
// since normally you expect tests to produce the same
23+
// results for everyone
24+
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
25+
paths.dotenv,
26+
].filter(Boolean);
27+
28+
// Load environment variables from .env* files. Suppress warnings using silent
29+
// if this file is missing. dotenv will never modify any environment variables
30+
// that have already been set. Variable expansion is supported in .env files.
31+
// https://github.com/motdotla/dotenv
32+
// https://github.com/motdotla/dotenv-expand
33+
dotenvFiles.forEach(dotenvFile => {
34+
if (fs.existsSync(dotenvFile)) {
35+
require('dotenv-expand')(
36+
require('dotenv').config({
37+
path: dotenvFile,
38+
})
39+
);
40+
}
41+
});
42+
43+
// We support resolving modules according to `NODE_PATH`.
44+
// This lets you use absolute paths in imports inside large monorepos:
45+
// https://github.com/facebook/create-react-app/issues/253.
46+
// It works similar to `NODE_PATH` in Node itself:
47+
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
48+
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
49+
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
50+
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
51+
// We also resolve them to make sure all tools using them work consistently.
52+
const appDirectory = fs.realpathSync(process.cwd());
53+
process.env.NODE_PATH = (process.env.NODE_PATH || '')
54+
.split(path.delimiter)
55+
.filter(folder => folder && !path.isAbsolute(folder))
56+
.map(folder => path.resolve(appDirectory, folder))
57+
.join(path.delimiter);
58+
59+
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
60+
// injected into the application via DefinePlugin in Webpack configuration.
61+
const REACT_APP = /^REACT_APP_/i;
62+
63+
function getClientEnvironment(publicUrl) {
64+
const raw = Object.keys(process.env)
65+
.filter(key => REACT_APP.test(key))
66+
.reduce(
67+
(env, key) => {
68+
env[key] = process.env[key];
69+
return env;
70+
},
71+
{
72+
// Useful for determining whether we’re running in production mode.
73+
// Most importantly, it switches React into the correct mode.
74+
NODE_ENV: process.env.NODE_ENV || 'development',
75+
// Useful for resolving the correct path to static assets in `public`.
76+
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
77+
// This should only be used as an escape hatch. Normally you would put
78+
// images into the `src` and `import` them in code to get their paths.
79+
PUBLIC_URL: publicUrl,
80+
}
81+
);
82+
// Stringify all values so we can feed into Webpack DefinePlugin
83+
const stringified = {
84+
'process.env': Object.keys(raw).reduce((env, key) => {
85+
env[key] = JSON.stringify(raw[key]);
86+
return env;
87+
}, {}),
88+
};
89+
90+
return { raw, stringified };
91+
}
92+
93+
module.exports = getClientEnvironment;

config/jest/cssTransform.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
// This is a custom Jest transformer turning style imports into empty objects.
4+
// http://facebook.github.io/jest/docs/en/webpack.html
5+
6+
module.exports = {
7+
process() {
8+
return 'module.exports = {};';
9+
},
10+
getCacheKey() {
11+
// The output is always the same.
12+
return 'cssTransform';
13+
},
14+
};

config/jest/fileTransform.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
5+
// This is a custom Jest transformer turning file imports into filenames.
6+
// http://facebook.github.io/jest/docs/en/webpack.html
7+
8+
module.exports = {
9+
process(src, filename) {
10+
const assetFilename = JSON.stringify(path.basename(filename));
11+
12+
if (filename.match(/\.svg$/)) {
13+
return `const React = require('react');
14+
module.exports = {
15+
__esModule: true,
16+
default: ${assetFilename},
17+
ReactComponent: React.forwardRef((props, ref) => ({
18+
$$typeof: Symbol.for('react.element'),
19+
type: 'svg',
20+
ref: ref,
21+
key: null,
22+
props: Object.assign({}, props, {
23+
children: ${assetFilename}
24+
})
25+
})),
26+
};`;
27+
}
28+
29+
return `module.exports = ${assetFilename};`;
30+
},
31+
};

0 commit comments

Comments
 (0)