ReactJs/Redux Invariant Violation: Could not find “store” in either the context or props of “Connect(LoginContainer)”

后端 未结 3 1499
深忆病人
深忆病人 2021-02-20 11:13

Not sure why I\'m getting this error, it happened when I added connect from redux to my Login component, so I could connect my store.

3条回答
  •  面向向阳花
    2021-02-20 11:36

    Redux recommends exporting the unconnected component for unit tests. See their docs.

    In login.js:

    // Named export for tests
    export class LoginContainer extends React.Component {
    }
    
    // Default export
    export default connect(null, mapDispatchToProps)(LoginContainer); 
    

    And in your test:

    // Import the named export, which has not gone through the connect function
    import { LoginContainer as Login } from './Login';
    

    You can then specify any props that would have come from the store directly on the component.

提交回复
热议问题