The document discusses higher order components (HOCs) in React. It begins by introducing HOCs as functions that take a component and return a new component. Various examples of HOCs are provided, including for purposes like code splitting, server side rendering, data tracking, and component logging. Key tips are provided, such as avoiding HOCs inside render and that refs are not passed through. The document also discusses how render props can be used as an alternative pattern to HOCs in some cases, and provides examples of common use cases like async data fetching and geolocation. It concludes by explaining that HOCs can also be created using a render prop approach.
13. Higher Order Functions
A function which takes one or more
arguments and returns a functions
Component
14. Higher Order Functions
A function which takes one or more
arguments and returns a functions
Component
A function which takes a component as an
argument and returns a new component
82. Be careful when using Render Props with
React.PureComponent
Handy Tip
83. Be careful when using Render Props with
React.PureComponent
Use function reference instead of arrow fn
Handy Tip
this.renderPosts = ({ posts }) => {
return posts.map(post => <Post post={post} />
}
<Posts
render={this.renderPosts}
/>
84. Common examples of render props
withRouter of React Router
Motion of React Motion
Downshift
UrQl