我正在尝试根据@Filipe Borges here(redux react-redux redux-persist)的建议,为我已经在我的React Native应用程序中工作的Redux状态管理添加持久性 . 我想要的只是用户创建的列表项(我存储在Redux中)应该在重新启动应用程序后可用 .
我根据redux-persist github README添加了似乎所需的代码,但 when I attempt to launch my app it either crashes immediately (after a few seconds of just a blank white screen), or gives me a cryptic error message/stacktrace 告诉我"Cannot Add a child that doesn't have a YogaNode to a parent with out a measure function"堆栈跟踪只包含库/核心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上 .
提前感谢您的帮助!
1 回答
这是因为 "loading..." 组件没有包装 < View > 和 < Text > ,尝试添加包装或创建加载组件,问题将得到解决 .