Skip to content

Commit 557ab30

Browse files
authored
Merge pull request reactjs#281 from daniellealexis/hoc-grammer-fix
Grammar Fixes on Higher Order Components Page
2 parents 5dfd480 + 1dd43b2 commit 557ab30

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

content/docs/higher-order-components.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function withSubscription(WrappedComponent, selectData) {
163163
}
164164
```
165165

166-
Note that an HOC doesn't modify the input component, nor does it use inheritance to copy its behavior. Rather, an HOC *composes* the original component by *wrapping* it in a container component. An HOC is a pure function with zero side-effects.
166+
Note that a HOC doesn't modify the input component, nor does it use inheritance to copy its behavior. Rather, a HOC *composes* the original component by *wrapping* it in a container component. A HOC is a pure function with zero side-effects.
167167

168168
And that's it! The wrapped component receives all the props of the container, along with a new prop, `data`, which it uses to render its output. The HOC isn't concerned with how or why the data is used, and the wrapped component isn't concerned with where the data came from.
169169

@@ -173,7 +173,7 @@ Like components, the contract between `withSubscription` and the wrapped compone
173173

174174
## Don't Mutate the Original Component. Use Composition.
175175

176-
Resist the temptation to modify a component's prototype (or otherwise mutate it) inside an HOC.
176+
Resist the temptation to modify a component's prototype (or otherwise mutate it) inside a HOC.
177177

178178
```js
179179
function logProps(InputComponent) {
@@ -217,7 +217,7 @@ You may have noticed similarities between HOCs and a pattern called **container
217217

218218
## Convention: Pass Unrelated Props Through to the Wrapped Component
219219

220-
HOCs add features to a component. They shouldn't drastically alter its contract. It's expected that the component returned from an HOC has a similar interface to the wrapped component.
220+
HOCs add features to a component. They shouldn't drastically alter its contract. It's expected that the component returned from a HOC has a similar interface to the wrapped component.
221221

222222
HOCs should pass through props that are unrelated to its specific concern. Most HOCs contain a render method that looks something like this:
223223

@@ -269,7 +269,7 @@ const ConnectedComment = connect(commentSelector, commentActions)(CommentList);
269269
```js
270270
// connect is a function that returns another function
271271
const enhance = connect(commentListSelector, commentListActions);
272-
// The returned function is an HOC, which returns a component that is connected
272+
// The returned function is a HOC, which returns a component that is connected
273273
// to the Redux store
274274
const ConnectedComment = enhance(CommentList);
275275
```
@@ -297,7 +297,7 @@ The `compose` utility function is provided by many third-party libraries includi
297297

298298
## Convention: Wrap the Display Name for Easy Debugging
299299

300-
The container components created by HOCs show up in the [React Developer Tools](https://github.com/facebook/react-devtools) like any other component. To ease debugging, choose a display name that communicates that it's the result of an HOC.
300+
The container components created by HOCs show up in the [React Developer Tools](https://github.com/facebook/react-devtools) like any other component. To ease debugging, choose a display name that communicates that it's the result of a HOC.
301301

302302
The most common technique is to wrap the display name of the wrapped component. So if your higher-order component is named `withSubscription`, and the wrapped component's display name is `CommentList`, use the display name `WithSubscription(CommentList)`:
303303

@@ -322,7 +322,7 @@ Higher-order components come with a few caveats that aren't immediately obvious
322322

323323
React's diffing algorithm (called reconciliation) uses component identity to determine whether it should update the existing subtree or throw it away and mount a new one. If the component returned from `render` is identical (`===`) to the component from the previous render, React recursively updates the subtree by diffing it with the new one. If they're not equal, the previous subtree is unmounted completely.
324324

325-
Normally, you shouldn't need to think about this. But it matters for HOCs because it means you can't apply an HOC to a component within the render method of a component:
325+
Normally, you shouldn't need to think about this. But it matters for HOCs because it means you can't apply a HOC to a component within the render method of a component:
326326

327327
```js
328328
render() {
@@ -338,18 +338,18 @@ The problem here isn't just about performance — remounting a component causes
338338

339339
Instead, apply HOCs outside the component definition so that the resulting component is created only once. Then, its identity will be consistent across renders. This is usually what you want, anyway.
340340

341-
In those rare cases where you need to apply an HOC dynamically, you can also do it inside a component's lifecycle methods or its constructor.
341+
In those rare cases where you need to apply a HOC dynamically, you can also do it inside a component's lifecycle methods or its constructor.
342342

343343
### Static Methods Must Be Copied Over
344344

345345
Sometimes it's useful to define a static method on a React component. For example, Relay containers expose a static method `getFragment` to facilitate the composition of GraphQL fragments.
346346

347-
When you apply an HOC to a component, though, the original component is wrapped with a container component. That means the new component does not have any of the static methods of the original component.
347+
When you apply a HOC to a component, though, the original component is wrapped with a container component. That means the new component does not have any of the static methods of the original component.
348348

349349
```js
350350
// Define a static method
351351
WrappedComponent.staticMethod = function() {/*...*/}
352-
// Now apply an HOC
352+
// Now apply a HOC
353353
const EnhancedComponent = enhance(WrappedComponent);
354354

355355
// The enhanced component has no static method
@@ -394,7 +394,7 @@ import MyComponent, { someFunction } from './MyComponent.js';
394394

395395
### Refs Aren't Passed Through
396396

397-
While the convention for higher-order components is to pass through all props to the wrapped component, it's not possible to pass through refs. That's because `ref` is not really a prop — like `key`, it's handled specially by React. If you add a ref to an element whose component is the result of an HOC, the ref refers to an instance of the outermost container component, not the wrapped component.
397+
While the convention for higher-order components is to pass through all props to the wrapped component, it's not possible to pass through refs. That's because `ref` is not really a prop — like `key`, it's handled specially by React. If you add a ref to an element whose component is the result of a HOC, the ref refers to an instance of the outermost container component, not the wrapped component.
398398

399399
If you find yourself facing this problem, the ideal solution is to figure out how to avoid using `ref` at all. Occasionally, users who are new to the React paradigm rely on refs in situations where a prop would work better.
400400

0 commit comments

Comments
 (0)