undefined不是一个对象(评估“Object.keys(inboundState)”)

3

只有在清除所有缓存后才会出现此错误。该应用程序是使用JavaScript和React Native开发的。我们正在使用Expo配合iOS模拟器、真实的iPhone和Android平板电脑。当应用程序重新加载时,程序开始运行没有问题。

这是来自iOS的错误信息:

undefined is not an object(evaluating 'Object.keys(inboundState)')

以下是随消息列出的附加信息。
defaultStateReconciller
autoRehydrate.js:66:14

dispatch
createStore.js:178:36

这是在Android上的表现方式 请求值不是一个对象的键。 附加信息列在消息下面。
defaultStateReconciller

dispatch
createStore.js:190:3

The yarn.lock file contains the following information:
"@redux-offline/redux-offline@^2.3.2": version "2.3.2" resolved "https://registry.yarnpkg.com/@redux-offline/redux-offline/-/redux-offline-2.3.2.tgz#ecdb324e198bd4aa6b965f651ec589f66c8f2605" dependencies: babel-runtime "^6.26.0" redux-persist "^4.5.0"
redux-persist@^4.5.0: version "4.10.2" resolved "https://registry.yarnpkg.com/redux-persist/-/redux-persist-4.10.2.tgz#8efdb16cfe882c521a78a6d0bfdfef2437f49f96" dependencies: json-stringify-safe "^5.0.1" lodash "^4.17.4" lodash-es "^4.17.4"
redux-persist@^5.9.1: version "5.9.1" resolved "https://registry.yarnpkg.com/redux-persist/-/redux-persist-5.9.1.tgz#83bd4abd526ef768f63fceee338fa9d8ed6552d6"
App.js

import { createStore, combineReducers, compose } from 'redux'
import { offline } from '@redux-offline/redux-offline'
import offlineConfig from '@redux-offline/redux-offline/lib/defaults'
import storage from 'redux-persist/lib/storage'
import { persistStore, persistReducer } from 'redux-persist'

const persistConfig = {
  key: 'root',
  storage
}

const persistedReducer = persistReducer(persistConfig, appReducer)

offlineConfig.effect = (effect, action) => {
  return fetchApi(effect.endpoint, effect.payload ? effect.payload : null,
    effect.method ? effect.method : null, effect.headers ? effect.headers : null)
}

export const store = createStore(
  persistedReducer,
  [],
  compose( 
    offline(offlineConfig)
  )
)
    return (
      <Provider store={store}>
        <PersistGate loading={null} persistor={persistor}>
          <Initialize />
          <Root>
            <RootStack />
          </Root>
        </PersistGate>
      </Provider>
    )


“这个错误只会在清除所有缓存后发生”...好的,所以你试图在加载之前使用某些东西。在清除缓存之前,它是从缓存中读取的(快速),但在你清除缓存之后,它需要从网络获取,因此在你使用它时还没有准备好。 - some
1
听起来你正在使用 redux-persist,能分享一下关于 redux-persist 的配置吗? - Prasun
正在使用redux-persist。我已经在yarn.lock中包含了对redux-persist的引用,以及来自App.js的配置。谢谢。 - Laius Zibetti
有什么解决方案吗?我也遇到了同样的问题。 - Jalal El-Shaer
1个回答

0

在Github上有一个关于这个问题的帖子 https://github.com/redux-offline/redux-offline/issues/362#issuecomment-552190934

尝试使用这个解决方法:

//redux-offline/node_modules/lib/autRehydrate.js:62
function defaultStateReconciler(state, inboundState, reducedState, log) {
  var newState = _extends({}, reducedState);
  if (typeof inboundState !== 'object') return newState;  // add this line.
  //...rest 
}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接