首页 文章

redux-form找不到商店

提问于
浏览
0

我是React的新手,我尝试将这个http://redux-form.com/5.2.5/#/getting-started?_k=vz58jr开始表单应用到我的组件,但是有问题:

Uncaught Invariant Violation:无法在“Connect(ReduxForm(ContactForm))”的上下文或道具中找到“store” . 将根组件包装在a中,或者将“store”显式传递为“Connect(ReduxForm(ContactForm))” .

我该怎么办?

3 回答

  • 0

    我使用过redux-mock-store,react-redux,酶和柴 .

    例如:

    singup

    class Signup extends Component { ... }
    
    Signup = reduxForm({
      form: 'newUser',
      fields: ['email', 'password', 'confirmPassword']
    })(Signup);
    
    Signup = connect(null, actions)(Signup);
    
    export default Signup;
    

    signup.test

    import React from 'react';
    import { shallow, mount } from 'enzyme';
    import { expect } from 'chai';
    import configureStore from 'redux-mock-store';
    import { Provider } from 'react-redux';
    import Signup from '../src/components/signup';
    
    let wrapper;
    const mockStore = configureStore([]);
    const store = mockStore({});
    
    describe('Signup', () => {
    
      beforeEach(() => {
          wrapper = mount(
            <Provider store={store}>
                <Signup />
            </Provider>
          );
      });
    
      it ('should have signup className', () => {
        expect(wrapper.find('.signup')).to.have.length(1);
      });
    
    });
    
  • 2

    我相信你需要与提供商一起通过商店 . 这是我用redux-form工作的github repo:https://github.com/joshuaslate/mern-starter/blob/master/client/src/index.js#L34

    这是关于通过提供商传递商店的视频:https://egghead.io/lessons/javascript-redux-passing-the-store-down-with-provider-from-react-redux

  • 1

    所有这些例子都是wrapped with Provider . 如何设置Redux存储超出了 redux-form 文档的范围 . 按照约书亚发布的链接了解这一点 .

相关问题