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: docs/docs/composition-vs-inheritance.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ function WelcomeDialog() {
44
44
}
45
45
```
46
46
47
-
[Try it on CodePen.](http://codepen.io/gaearon/pen/ozqNOV?editors=0010)
47
+
[Try it on CodePen.](https://codepen.io/gaearon/pen/ozqNOV?editors=0010)
48
48
49
49
Anything inside the `<FancyBorder>` JSX tag gets passed into the `FancyBorder` component as a `children` prop. Since `FancyBorder` renders `{props.children}` inside a `<div>`, the passed elements appear in the final output.
50
50
@@ -77,7 +77,7 @@ function App() {
77
77
}
78
78
```
79
79
80
-
[Try it on CodePen.](http://codepen.io/gaearon/pen/gwZOJp?editors=0010)
80
+
[Try it on CodePen.](https://codepen.io/gaearon/pen/gwZOJp?editors=0010)
81
81
82
82
React elements like `<Contacts />` and `<Chat />` are just objects, so you can pass them as props like any other data.
83
83
@@ -110,7 +110,7 @@ function WelcomeDialog() {
110
110
}
111
111
```
112
112
113
-
[Try it on CodePen.](http://codepen.io/gaearon/pen/kkEaOZ?editors=0010)
113
+
[Try it on CodePen.](https://codepen.io/gaearon/pen/kkEaOZ?editors=0010)
114
114
115
115
Composition works equally well for components defined as classes:
116
116
@@ -160,7 +160,7 @@ class SignUpDialog extends React.Component {
160
160
}
161
161
```
162
162
163
-
[Try it on CodePen.](http://codepen.io/gaearon/pen/gwZbYa?editors=0010)
163
+
[Try it on CodePen.](https://codepen.io/gaearon/pen/gwZbYa?editors=0010)
Copy file name to clipboardExpand all lines: docs/docs/lifting-state-up.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ class Calculator extends React.Component {
56
56
}
57
57
```
58
58
59
-
[Try it on CodePen.](http://codepen.io/valscion/pen/VpZJRZ?editors=0010)
59
+
[Try it on CodePen.](https://codepen.io/gaearon/pen/ZXeOBm?editors=0010)
60
60
61
61
## Adding a Second Input
62
62
@@ -110,7 +110,7 @@ class Calculator extends React.Component {
110
110
}
111
111
```
112
112
113
-
[Try it on CodePen.](http://codepen.io/valscion/pen/GWKbao?editors=0010)
113
+
[Try it on CodePen.](https://codepen.io/gaearon/pen/jGBryx?editors=0010)
114
114
115
115
We have two inputs now, but when you enter the temperature in one of them, the other doesn't update. This contradicts our requirement: we want to keep them in sync.
116
116
@@ -296,7 +296,7 @@ class Calculator extends React.Component {
296
296
}
297
297
```
298
298
299
-
[Try it on CodePen.](http://codepen.io/valscion/pen/jBNjja?editors=0010)
299
+
[Try it on CodePen.](https://codepen.io/gaearon/pen/WZpxpz?editors=0010)
300
300
301
301
Now, no matter which input you edit, `this.state.temperature` and `this.state.scale` in the `Calculator` get updated. One of the inputs gets the value as is, so any user input is preserved, and the other input value is always recalculated based on it.
@@ -77,19 +100,27 @@ class Parent extends React.Component {
77
100
}
78
101
79
102
handleClick() {
80
-
// This will fire when the button in Child is clicked, updating Parent's state,
81
-
// even though Child is not a direct descendant in the DOM.
103
+
// This will fire when the button in Child is clicked,
104
+
// updating Parent's state, even though button
105
+
// is not direct descendant in the DOM.
82
106
this.setState(prevState => ({
83
107
clicks: prevState.clicks + 1
84
108
}));
85
109
}
86
110
87
111
render() {
88
112
return (
89
-
<div onClick={this.onClick}>
113
+
<div onClick={this.handleClick}>
90
114
<p>Number of clicks: {this.state.clicks}</p>
91
-
<p>Open up the browser DevTools to observe that the button is not a child the div with onClick handler.</p>
92
-
{ReactDOM.createPortal(<Child />, modalRoot)}
115
+
<p>
116
+
Open up the browser DevTools
117
+
to observe that the button
118
+
is not a child the div
119
+
with onClick handler.
120
+
</p>
121
+
<Modal>
122
+
<Child />
123
+
</Modal>
93
124
</div>
94
125
);
95
126
}
@@ -105,10 +136,9 @@ function Child() {
105
136
);
106
137
}
107
138
108
-
109
139
ReactDOM.render(<Parent />, appRoot);
110
140
```
111
141
112
-
[Try this example on CodePen](https://codepen.io/gaearon/pen/jGBWpE).
142
+
[Try it on CodePen.](https://codepen.io/gaearon/pen/jGBWpE).
113
143
114
144
Catching an event bubbling up from a portal in a parent component allows the development of more flexible abstractions that are not inherently reliant on portals. For example, if you render a `<Modal />` component, the parent can capture its events regardless of whether it's implemented using portals.
Copy file name to clipboardExpand all lines: docs/docs/reference-dom-elements.md
+16-20
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,19 @@ The `value` attribute is supported by `<input>` and `<textarea>` components. You
98
98
99
99
## All Supported HTML Attributes
100
100
101
-
React supports all `data-*` and `aria-*` attributes as well as these attributes:
101
+
As of React 16, any standard [or custom](/react/blog/2017/09/08/dom-attributes-in-react-16.html) DOM attributes are fully supported.
102
+
103
+
React has always provided a JavaScript-centric API to the DOM. Since React components often take both custom and DOM-related props, React uses the `camelCase` convention just like the DOM APIs:
104
+
105
+
```js
106
+
<div tabIndex="-1"/>// Just like node.tabIndex DOM API
107
+
<div className="Button"/>// Just like node.className DOM API
108
+
<input readOnly={true} />// Just like node.readOnly DOM API
109
+
```
110
+
111
+
These props work similarly to the corresponding HTML attributes, with the exception of the special cases documented above.
112
+
113
+
Some of the DOM attributes supported by React include:
102
114
103
115
```
104
116
accept acceptCharset accessKey action allowFullScreen allowTransparency alt
Copy file name to clipboardExpand all lines: docs/docs/thinking-in-react.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ Now that we've identified the components in our mock, let's arrange them into a
61
61
62
62
## Step 2: Build A Static Version in React
63
63
64
-
<pdata-height="600"data-theme-id="0"data-slug-hash="vXpAgj"data-default-tab="js"data-user="lacker"data-embed-version="2"class="codepen">See the Pen <ahref="http://codepen.io/lacker/pen/vXpAgj/">Thinking In React: Step 2</a> on <ahref="http://codepen.io">CodePen</a>.</p>
64
+
<pdata-height="600"data-theme-id="0"data-slug-hash="BwWzwm"data-default-tab="js"data-user="lacker"data-embed-version="2"class="codepen">See the Pen <ahref="https://codepen.io/gaearon/pen/BwWzwm">Thinking In React: Step 2</a> on <ahref="http://codepen.io">CodePen</a>.</p>
Now that you have your component hierarchy, it's time to implement your app. The easiest way is to build a version that takes your data model and renders the UI but has no interactivity. It's best to decouple these processes because building a static version requires a lot of typing and no thinking, and adding interactivity requires a lot of thinking and not a lot of typing. We'll see why.
@@ -106,7 +106,7 @@ So finally, our state is:
106
106
107
107
## Step 4: Identify Where Your State Should Live
108
108
109
-
<pdata-height="600"data-theme-id="0"data-slug-hash="ORzEkG"data-default-tab="js"data-user="lacker"data-embed-version="2"class="codepen">See the Pen <ahref="http://codepen.io/lacker/pen/ORzEkG/">Thinking In React: Step 4</a> by Kevin Lacker (<ahref="http://codepen.io/lacker">@lacker</a>) on <ahref="http://codepen.io">CodePen</a>.</p>
109
+
<pdata-height="600"data-theme-id="0"data-slug-hash="qPrNQZ"data-default-tab="js"data-user="lacker"data-embed-version="2"class="codepen">See the Pen <ahref="https://codepen.io/gaearon/pen/qPrNQZ">Thinking In React: Step 4</a> on <ahref="http://codepen.io">CodePen</a>.</p>
OK, so we've identified what the minimal set of app state is. Next, we need to identify which component mutates, or *owns*, this state.
@@ -132,7 +132,7 @@ You can start seeing how your application will behave: set `filterText` to `"bal
132
132
133
133
## Step 5: Add Inverse Data Flow
134
134
135
-
<pdata-height="600"data-theme-id="0"data-slug-hash="qRqmjd"data-default-tab="js,result"data-user="rohan10"data-embed-version="2"data-pen-title="Thinking In React: Step 5"class="codepen">See the Pen <ahref="http://codepen.io/rohan10/pen/qRqmjd">Thinking In React: Step 5</a> on <ahref="http://codepen.io">CodePen</a>.</p>
135
+
<pdata-height="600"data-theme-id="0"data-slug-hash="LzWZvb"data-default-tab="js,result"data-user="rohan10"data-embed-version="2"data-pen-title="Thinking In React: Step 5"class="codepen">See the Pen <ahref="https://codepen.io/gaearon/pen/LzWZvb">Thinking In React: Step 5</a> on <ahref="http://codepen.io">CodePen</a>.</p>
So far, we've built an app that renders correctly as a function of props and state flowing down the hierarchy. Now it's time to support data flowing the other way: the form components deep in the hierarchy need to update the state in `FilterableProductTable`.
0 commit comments