【问题标题】:"Element type is invalid" Store import error in redux-persist in react native,“元素类型无效”在 react native 中的 redux-persist 中存储导入错误,
【发布时间】:2021-07-18 12:26:45
【问题描述】:

我找不到可能出现导入错误的位置。错误是:

错误:元素类型无效:应为字符串(对于内置 组件)或类/函数(用于复合组件),但得到: 不明确的。您可能忘记从文件中导出组件 它是在中定义的,或者您可能混淆了默认导入和命名导入。

查看App的渲染方法。

此错误位于: 在提供者中(在 App.js:12) 在 App 中(由 ExpoRoot 创建) ...

configureStore.js

import { createStore, combineReducers, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import logger from 'redux-logger';
import { campsites } from './campsites';
import { comments } from './comments';
import { promotions } from './promotions';
import { partners } from './partners';
import { favorites } from './favorites'
import { persistStore, persistCombineReducers } from 'redux-persist';
import storage  from 'redux-persist/es/storage'

const config = {
    key: 'root',
    storage,
    debug: true
}
    export const ConfigureStore = () => {
        const store = createStore(
            persistCombineReducers(config, {
                campsites,
                comments,
                partners,
                promotions,
                favorites
            }),
            applyMiddleware(thunk, logger)
        );
    
        const persistor = persistStore(store)
    
        return { persistor, store };
    };

App.js

import React from 'react';
import Main from './components/MainComponent';
import { Provider } from 'react-redux'
import { ConfigureStore } from './redux/configureStore';
import { PersistGate } from 'redux-persist';
import Loading from './components/LoadingComponent'

const { persistor, store } = ConfigureStore();

export default function App() {
    return (
        <Provider store={store}>
            <PersistGate
                loading={<Loading />}
                persistor={persistor}>
                <Main />
            </PersistGate>
        </Provider>
    );
}

【问题讨论】:

    标签: reactjs react-native redux react-redux redux-persist


    【解决方案1】:

    在 PersistGate 上导入错误。应该是:

    import { PersistGate } from 'redux-persist/es/integration/react';
    

    【讨论】:

      猜你喜欢
      • 2021-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      • 2021-02-28
      • 2021-07-29
      • 2018-02-07
      相关资源
      最近更新 更多