Skip to content

Commit 1b105ff

Browse files
Merge remote-tracking branch 'FrontendMasters/master'
2 parents 25c77a6 + a2138e1 commit 1b105ff

File tree

33 files changed

+124
-112
lines changed

33 files changed

+124
-112
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# React Enlightenment [DRAFT]
1+
# React Enlightenment
22

33
Written by [Cody Lindley](http://codylindley.com/) sponsored by — [Frontend Masters](https://frontendmasters.com/)
44

SUMMARY.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
* [6.3 Return One Starting Node/Component](basic-react-components/6.3.md)
3131
* [6.4 Referring to a Component Instance](basic-react-components/6.4.md)
3232
* [6.5 Defining Events on Components](basic-react-components/6.5.md)
33-
* [6.5 Composing Components](basic-react-components/6.6.md)
34-
* [6.6 Grokking Component Lifecycle's](basic-react-components/6.7.md)
35-
* [6.7 Accessing Children Components/Nodes](basic-react-components/6.8.md)
36-
* [6.8 Using ref Attribute](basic-react-components/6.9.md)
37-
* [6.9 Re-rendering A Component](basic-react-components/6.10.md)
33+
* [6.6 Composing Components](basic-react-components/6.6.md)
34+
* [6.7 Grokking Component Lifecycle's](basic-react-components/6.7.md)
35+
* [6.8 Accessing Children Components/Nodes](basic-react-components/6.8.md)
36+
* [6.9 Using ref Attribute](basic-react-components/6.9.md)
37+
* [6.10 Re-rendering A Component](basic-react-components/6.10.md)
3838
* [7. React Component Props](react-props.md)
3939
* [7.1 What Are Component Props?](react-props/7.1.md)
4040
* [7.2 Sending Component Props](react-props/7.2.md)

basic-react-components/6.2.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ A React component that will potentially contain `state` can be created by callin
44

55
<table>
66
<tr>
7-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#render"><code>render</code></a></td>
7+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#render"><code>render()</code></a></td>
88
<td>A required value, typically a function that returns React nodes, other React components, or <code>null</code>/<code>false</code></td>
99
</tr>
1010

1111
<tr>
12-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#getinitialstate"><code>getInitialState</code></a></td>
13-
<td>Object containing initial value of <code>this.state</code></td>
12+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#getinitialstate"><code>getInitialState()</code></a></td>
13+
<td>Function which returns an object containing initial value of <code>this.state</code></td>
1414
</tr>
1515

1616
<tr>
17-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#getdefaultprops"><code>getDefaultProps</code></a></td>
18-
<td> Object containing values to be set on <code>this.props</code></td>
17+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#getdefaultprops"><code>getDefaultProps()</code></a></td>
18+
<td>Function which returns an object containing values to be set on <code>this.props</code></td>
1919
</tr>
2020

2121
<tr>
@@ -39,37 +39,37 @@ A React component that will potentially contain `state` can be created by callin
3939
</tr>
4040

4141
<tr>
42-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#displayname"><code>componentWillMount</code></a></td>
42+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#displayname"><code>componentWillMount()</code></a></td>
4343
<td>Callback function invoked once immediately before the initial rendering occurs</td>
4444
</tr>
4545

4646
<tr>
47-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount"><code>componentDidMount</code></a></td>
47+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount"><code>componentDidMount()</code></a></td>
4848
<td>Callback function invoked immediately after the initial rendering occurs</td>
4949
</tr>
5050

5151
<tr>
52-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#updating-componentwillreceiveprops"><code>componentWillReceiveProps</code></a></td>
52+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#updating-componentwillreceiveprops"><code>componentWillReceiveProps()</code></a></td>
5353
<td>Callback function invoked when a component is receiving new props</td>
5454
</tr>
5555

5656
<tr>
57-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#updating-shouldcomponentupdate"><code>shouldComponentUpdate</code></a></td>
57+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#updating-shouldcomponentupdate"><code>shouldComponentUpdate()</code></a></td>
5858
<td>Callback function invoked before rendering when new props or state are being received</td>
5959
</tr>
6060

6161
<tr>
62-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#updating-componentwillupdate"><code>componentWillUpdate</code></a></td>
62+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#updating-componentwillupdate"><code>componentWillUpdate()</code></a></td>
6363
<td>Callback function invoked immediately before rendering when new props or state are being received.</td>
6464
</tr>
6565

6666
<tr>
67-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#updating-componentdidupdate"><code>componentDidUpdate</code></a></td>
67+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#updating-componentdidupdate"><code>componentDidUpdate()</code></a></td>
6868
<td>Callback function invoked immediately after the component&#39;s updates are flushed to the DOM</td>
6969
</tr>
7070

7171
<tr>
72-
<td><a href="http://facebook.github.io/react/docs/component-specs.html#unmounting-componentwillunmount"><code>componentWillUnmount</code></a></td>
72+
<td><a href="http://facebook.github.io/react/docs/component-specs.html#unmounting-componentwillunmount"><code>componentWillUnmount()</code></a></td>
7373
<td>Callback function invoked immediately before a component is unmounted from the DOM</td>
7474
</tr>
7575
</table>
@@ -140,12 +140,12 @@ Once a component is mounted (i.e created) you can use the component API. The api
140140
</tr>
141141
</table>
142142

143-
The most commonly used component API method used will is `setState()`. Its usage will be covered in the React Component State chapter.
143+
The most commonly used component API method is `setState()`. Its usage will be covered in the React Component State chapter.
144144

145145
#### Notes
146146

147147
* The component callback configuration options (`componentWillUnmount`, `componentDidUpdate`, `componentWillUpdate`, `shouldComponentUpdate`, `componentWillReceiveProps`, `componentDidMount`, `componentWillMount`) are also known as "lifecycle methods" because these various methods are executed at specific points in a component's life.
148-
* The `React.createClass()` function is a convenience function that creates component instances (via JavaScript `new` keyword) for you.
148+
* The `React.createClass()` function is a convenience function that creates component instances for you (via JavaScript `new` keyword).
149149
* The `render()` function should be a pure function. Which means:
150150

151151
>it does not modify component state, it returns the same result each time it's invoked, and it does not read from or write to the DOM or otherwise interact with the browser (e.g., by using `setTimeout`). If you need to interact with the browser, perform your work in `componentDidMount()` or the other lifecycle methods instead. Keeping `render()` pure makes server rendering more practical and makes components easier to think about.

basic-react-components/6.3.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Components Return One Node/Component
22

3-
The `render` configuration value defined when creating a component should return only one React node (or, component). This one node/component can contained any number of children. In the code below the `<reactNode>` is the starting node. In side of this node any number of sibling and child nodes can be returned.
3+
The `render` configuration value defined when creating a component should return only one React node (or, component). This one node/component can contain any number of children. In the code below the `<reactNode>` is the starting node. Inside of this node any number of sibling and child nodes can be returned.
44

55
> [source code](https://jsfiddle.net/fv26rjdL/#tabs=js,result,html,resources)
66
77
Note that if you want to return React nodes on more than one line (taking advantage of whitespace) you will have to surround the returned value in `()`. In the code below the JSX defining (i.e., rendered) the `MyComponent` is returned in `()`.
88

99
> [source code](https://jsfiddle.net/e2awasnk/#tabs=js,result,html,resources)
1010
11-
An error will occur if more than one starting React node is attempted to be return. If you think about it, the error occurs because returning two `React.createElement()` functions isn't possible with JavaScript.
11+
An error will occur if more than one starting React node is attempted to be returned. If you think about it, the error occurs because returning two `React.createElement()` functions isn't possible with JavaScript.
1212

1313
> [source code](https://jsfiddle.net/xe5kkpub/#tabs=js,result,html,resources)
1414

basic-react-components/6.4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ The other way to gain a reference to a component instance involves making use of
1212
1313
#### Notes
1414

15-
* The `this` keyword will commonly be used from within a component to access instance properties like `this.props.[NAME OF PROP]`, `this.props.children`, and `this.state`,. It will also be used to call class methods/properties, that all components share like `this.setState`, `this.replaceState()`.
15+
* The `this` keyword will commonly be used from within a component to access instance properties like `this.props.[NAME OF PROP]`, `this.props.children`, and `this.state`,. It will also be used to call class methods/properties, that all components share like `this.setState` and `this.replaceState()`.

basic-react-components/6.5.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Defining Events on Components
22

3-
Events can be added to React nodes inside of a components `render` configuration option (discussed in Ch. 4 - 4.7 and Ch. 5 - 5.8).
3+
Events can be added to React nodes inside of a components `render` configuration option (discussed in Ch. 4 section 4.7 and Ch. 5 section 5.8).
44

55
In the code example, two React events (i.e., `onClick` & `onMouseOver`) are set on React nodes (via JSX) using what looks like component props.
66

77
> [source code](https://jsfiddle.net/sjL64ogk/#tabs=js,result,html,resources)
88
9-
Basically, React when rendering a component looks for special React prop events (e.g., `onClick`) and treats these props differently from other props (all react events shown in table below). Obviously the difference being, that eventing in the real DOM is being wired up behind the scenes.
9+
Basically, React when rendering a component looks for special React prop events (e.g., `onClick`) and treats these props differently from other props (all React events shown in table below). Obviously the difference being, that eventing in the real DOM is being wired up behind the scenes.
1010

1111
Part of this wiring is auto binding the context of the handler/callback to the scope of the component instance. In the code example below the value of `this` inside of the handlers/callbacks will reference the component instance itself.
1212

@@ -152,7 +152,7 @@ shiftKey,
152152
#### Notes
153153

154154
* React normalizes events so that they behave consistently across different browsers.
155-
* Events in React are triggered on the bubbling phase. To trigger an event on the capturing phase add the word "Capture" to the event name (e.g., `onClick` would become `onClickCapture`).
155+
* Events in React are triggered on the bubbling phase. To trigger an event on the capturing phase add the word "Capture" to the end of the event name (e.g., `onClick` would become `onClickCapture`).
156156
* If you need the browser event details for a given event you can access this by using the `nativeEvent` property found in the SyntheticEvent object passed into React event hander/callbacks.
157157
* React does not actually attach events to the nodes themselves, it uses [event delegation](http://domenlightenment.com/#11.14).
158158
* `e.stopPropagation()` or `e.preventDefault()` should be triggered manually to [stop](http://domenlightenment.com/#11.9) event [propagation](http://domenlightenment.com/#11.10) instead of `returning false;`.

basic-react-components/6.6.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ In the code below the `BadgeList` component contains/owns the `BadgeBill` and `B
66

77
> [source code](https://jsfiddle.net/codylindley/0m9s4ow7/#tabs=js,result,html,resources)
88
9+
This code was purposefully simplistic in order to demonstrate component composition. In the next chapter, we will look at how the code will typically be written making use of props to create a generic `Badge` component. The generic Badge component can take any name value v.s. creating a unique badge and hard coding the name in the component.
10+
911
### Notes
1012

11-
* This code was purposefully simplistic in order to demonstrate component composition. In the next chapter will look at how the code will typically be written making use of props to create a generic `Badge` component. The generic Badge component can that take any name value v.s. creating a unique badge and hard coding the name in the component.
12-
* A key tenet of maintainable front-ends composable components. React components by design are meant to contain other React components.
13+
* A key tenet of maintainable UI are composable components. React components by design are meant to contain other React components.
1314
* Notice how HTML and previously defined components are mixed together in the `render()` configuration function.

basic-react-components/6.7.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Grokking Component Lifecycle's
22

3-
React components live certain life events that are called lifecycle events. These lifecycle's events are tied to lifecycle methods. I discussed several of these methods at the start of this chapter when discusses the creation of components.
3+
React components live certain life events that are called lifecycle events. These lifecycle's events are tied to lifecycle methods. I discussed several of these methods at the start of this chapter when discussing the creation of components.
44

55
The lifecycle methods provide hooks into the phases and the nature of a component. In the code example, taken from section 6.2, I am console logging the occurrence of the lifecycle events `componentDidMount`, `componentWillUnmount`, and `getInitialState` lifecycle methods.
66

@@ -75,7 +75,7 @@ Below I show a table for each category and the containing lifecycle methods.
7575

7676
### Notes
7777

78-
* `componentDidMount` and `componentDidUpdate` is a good places to put other libraries' logic.
78+
* `componentDidMount` and `componentDidUpdate`are good places to put other libraries' logic.
7979
* Read [React In-depth](https://developmentarc.gitbooks.io/react-indepth/content/life_cycle/introduction.html) for a detailed look into the React component lifecycle events
8080
* Mounting Phase follows this order:
8181
<ol>

basic-react-components/6.8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Accessing Children Components/Nodes
22

3-
If a component, when used, contains child components or React nodes inside of the component (e.g., `<Parent><Child /></Parent>` or `<Parent><span>test<span></Parent>`) these React node or component instances can be accessed by using `this.props.children`.
3+
If a component, when used, contains child React components or React nodes inside of the component (e.g., `<Parent><Child /></Parent>` or `<Parent><span>test<span></Parent>`) these React node or component instances can be accessed by using `this.props.children`.
44

55
In the code below the `Parent` component when used, contains two `<div>` React node children, which contains React text nodes. All of the children instances, inside of the component are accessible using `this.props.children`. In the code below I access these children inside of the `Parent` `componentDidMount` lifecycle function.
66

basic-react-components/6.9.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The `ref` attribute makes it possible to store a reference to a particular React element or component returned by the component `render()` configuration function. This can be valuable when you need a reference, from within a component, to some element or component contained within the `render()` function.
44

5-
To make a reference place the `ref` attribute with a function value on any React element or component. Then, inside of the function, the first parameter within the scope of the function will be a reference to the element or component the `ref` is on.
5+
To make a reference, place the `ref` attribute with a function value on any React element or component. Then, inside of the function, the first parameter within the scope of the function will be a reference to the element or component the `ref` is on.
66

77
For example in the code below I am console logging the reference out for each `ref`.
88

@@ -17,7 +17,7 @@ A common use for `ref`'s are to store a reference on the component instance. In
1717
### Notes
1818

1919
* Refs can't be attached to a stateless function because the component does not have a backing instance.
20-
* You might see a `ref` attribute with a string instead of a function, this is called a string `ref` and will likely be deprecated in the future. Function `ref`s are preferred.
20+
* You might see a `ref` attribute with a string instead of a function; this is called a string `ref` and will likely be deprecated in the future. Function `ref`s are preferred.
2121
* The `ref` callback function is called immediately after the component is mounted.
2222
* References to a component instance allow one to call custom methods on the component if any are exposed when defining it.
2323
* Writing refs with inline function expressions means React will see a different function object on every update, `ref` will be called with null immediately before it's called with the component instance. I.e., When the referenced component is unmounted and whenever the `ref` changes, the old `ref` will be called with `null` as an argument.

0 commit comments

Comments
 (0)