Use connect on HOC compoennts
See original GitHub issueIs there any way one could use connect on HOCs and fetch a data from store?
import React from 'react';
import {connect} from 'react-redux';
function withCurrentUser(Component) {
return function(...props) {
return <Component currentUser={/* Pass current user fetched from store here */} {...props} />
}
}
function mapStateToProps(state) {
return {
currentUser: state.user
}
}
export default connect(mapStateToProps)(withCurrentUser);
Issue Analytics
- State:
- Created 6 years ago
- Reactions:15
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How to connect a HOC with React and Redux - Level Up Coding
Create a loading component using HOCs for fetching data from your server and have fun! ; Fetch all data from your server API...
Read more >React Redux use HOC with connected component
Here is a simple example how it works const AppWrapper = MainComponent => class extends Component{ componentWillmount(){ this.props.
Read more >Connect | React Redux
The connect() function connects a React component to a Redux store. It provides its connected component with the pieces of the data it...
Read more >Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
Read more >Connected Higher Order Component (HOC) | by Karan Jariwala
One way to go about doing this is to Connect the components with the Redux Store and then to add appropriate disable or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not written that way, since
connect
expects an actual component type as the second function’s parameter. However, this should work:At least, I think that will work. I know composing HOCs works in general, just not sure on the exact syntax. Hopefully that at least points you in a useful direction.
It’s a bit old, but you could achieve this with a little modification of your code: