我正在尝试根据@Filipe Borges here(redux + react-redux + redux-persist)的建议,为我已经在我的React Native应用程序中工作的Redux状态管理添加持久性。我想要的只是用户创建的列表项(我存储在Redux中)应该在重新启动应用程序后可用。
我根据redux-persist github README添加了所需的代码,但当我尝试启动我的应用时,它会立即崩溃(几秒钟之后只有一个空白的白色屏幕) ,或者给我一个神秘的错误消息/ stacktrace 告诉我“不能将没有瑜伽节点的孩子添加到没有测量功能的父节点”,堆栈跟踪只包含库/核心React Native代码(meaing我真的不知道在哪里看)。
为了澄清,在添加redux-persist之前,redux和react-redux工作得很好。
以下是我store.js
的样子:
import { createStore, applyMiddleware } from "redux";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";
import logger from "redux-logger";
import reducers from "./reducers";
// configure middleware
let middleware = [];
if (process.env.NODE_ENV === "development") {
middleware.push(logger);
}
// configure persistance
const persistConfig = {
key: "root",
storage: storage,
};
const persistedReducers = persistReducer(persistConfig, reducers);
export default function configureStore() {
// finalize store setup
let store = createStore(persistedReducers, applyMiddleware(...middleware));
let persistor = persistStore(store);
return { store, persistor };
}
和我的App.js
:
import React, { Component } from 'react';
import Expo from "expo";
import Navigator from "./app/config/routes";
// store and state management
import { Provider } from "react-redux";
import configureStore from "./app/redux/store";
let { store, persistor } = configureStore();
import { PersistGate } from "redux-persist/lib/integration/react";
export default class App extends Component {
constructor() {
super();
Expo.ScreenOrientation.allow(Expo.ScreenOrientation.Orientation.PORTRAIT_UP);
}
render() {
return (
<Provider store={store}>
<PersistGate loading="loading..." persistor={persistor}>
<Navigator />
</PersistGate>
</Provider>
);
}
}
关于我的环境的说明;我的应用程序是一个独立的Expo应用程序:
"dependencies": {
"expo": "^24.0.0",
"react": "16.0.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-24.0.0.tar.gz",
"react-navigation": "^1.0.0-beta.21",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-persist": "^5.4.0",
...etc, some more unrelated packages
}
在MacOS High Sierra开发的Android 7上运行。
提前感谢您的帮助!
答案 0 :(得分:1)
这是因为&#34; loading ...&#34; 组件没有包装&lt;查看&gt; 和&lt;文字&gt; ,尝试添加换行或创建加载组件,问题就解决了。