【问题标题】:redux-form couldn't find storeredux-form 找不到商店
【发布时间】:2016-09-30 22:25:15
【问题描述】:

我是 React 新手,我尝试将此 http://redux-form.com/5.2.5/#/getting-started?_k=vz58jr 启动表单应用到我的组件,但出现了问题:

未捕获的不变违规:在“Connect(ReduxForm(ContactForm))”的上下文或道具中找不到“存储”。要么包装 a 中的根组件,或显式将“store”作为道具传递 到“连接(ReduxForm(ContactForm))”。

我能用这个做什么?

【问题讨论】:

    标签: redux redux-form


    【解决方案1】:

    我用过 redux-mock-store、react-redux、enzyme 和 chai。

    例如:

    唱歌

    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 存储库: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

      【讨论】:

        【解决方案3】:

        所有这些例子都是wrapped with Provider。如何设置 Redux 存储超出了 redux-form 文档的范围。按照 Joshua 发布的链接了解相关信息。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-06-23
          • 1970-01-01
          • 2018-03-14
          • 1970-01-01
          • 2018-12-25
          • 2019-11-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多