React-redux connect() cannot wrap component defined as a class extending React.Component

前端 未结 2 1560
离开以前
离开以前 2021-02-19 05:59

I may be missing something, but I can\'t find any example where connect() wraps a component defined as a class (extending React.Component), it always

相关标签:
2条回答
  • 2021-02-19 06:48

    You can wrap a React component, whether it's a class or a functional component, with react-redux connect.

    class MyDiv extends React.Component {
      render() {
        return <div>hi</div>
      }
    }
    
    export default connect(({ stateStuff }) => ({ stateStuff }))(MyDiv);
    
    0 讨论(0)
  • 2021-02-19 06:54

    you actually are correctly wrapping your component class in connect(). Your problem is elsewhere, in routes/Home/index.js:

    import HomeContainer from './containers/HomeContainer'
    
    export default (store) => {
      component : HomeContainer(store)
    }
    

    the default export of HomeContainer is the higher-order class returned by connect. You're then trying to use HomeContainer as a function here, just like your console error says:

        HomeContainer(store)
    

    .

    0 讨论(0)
提交回复
热议问题