将React-Redux从v1.x转换到v2.x

时间:2018-12-13 12:43:41

标签: reactjs react-native redux react-redux

所以我还是一个新手,我发现的所有教程都使用了React-Redux v1的示例,但是现在我的代码甚至都无法编译,这给了我这个错误: <提供者>不支持即时更改store。您最有可能看到此错误,因为您已更新到Redux 2.x和React Redux 2.x,它们不再自动热重装减速器。有关迁移说明,请参见https://github.com/reduxjs/react-redux/releases/tag/v2.0.0我尝试按照链接上的示例进行操作,但失败了。.这是我的代码,现在进行任何更改:

import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import firebase from 'firebase';
import ReduxThunk from 'redux-thunk';
import reducers from './reducers';
import AppContainer from './AppNavigator';

console.disableYellowBox = true;

class App extends Component {
    async componentDidMount() {
        const config = {
            apiKey: "",
            authDomain: "",
            databaseURL: "",
            projectId: "",
            storageBucket: "",
            messagingSenderId: ""
          };
        await firebase.initializeApp(config);
    }

    render() {
        const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));

        return (
            <Provider store={store}>
                <AppContainer />
            </Provider>
        );
    }
}

export default App;

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。我不得不将createStore行移到课程之外