mirror of
https://github.com/facebook/react.git
synced 2026-02-26 00:55:04 +00:00
Update higher-order-components.md (#8780)
This commit is contained in:
committed by
Dan Abramov
parent
3bc5595dfd
commit
20c4aac9ec
@@ -64,7 +64,8 @@ class CommentList extends React.Component {
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Later, you write a component for subscribing to a single blog post, which follows a similar pattern:
|
||||
@@ -95,7 +96,8 @@ class BlogPost extends React.Component {
|
||||
|
||||
render() {
|
||||
return <BlogPost blogPost={this.state.blogPost} />;
|
||||
}}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`CommentList` and `BlogPost` aren't identical — they call different methods on `DataSource`, and they render different output. But much of their implementation is the same:
|
||||
@@ -157,7 +159,7 @@ function withSubscription(WrappedComponent, selectData) {
|
||||
// Notice that we pass through any additional props
|
||||
return <WrappedComponent data={this.state.data} {...this.props} />;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user