React native Redux持续不同步
我使用react native with expo,我有redux persist,我可以很好地使用它从应用商店获取状态,但是当我重新加载应用程序时,状态不会持久 我想知道是否还有其他步骤使您的状态与异步存储状态同步 我使用分派方法更改状态,然后打印更新的状态-一切正常。 然后我打印存储在asyc存储器中的内容,只存储旧状态 我也在web浏览器上这样做过,看到了同样的情况,应用程序中的状态更新很好,然后当我检查存储时,没有任何更改,它仍然将'initialState'变量作为状态,并且更新没有添加到存储中 这是我的外部组件:React native Redux持续不同步,react-native,redux,react-redux,redux-persist,React Native,Redux,React Redux,Redux Persist,我使用react native with expo,我有redux persist,我可以很好地使用它从应用商店获取状态,但是当我重新加载应用程序时,状态不会持久 我想知道是否还有其他步骤使您的状态与异步存储状态同步 我使用分派方法更改状态,然后打印更新的状态-一切正常。 然后我打印存储在asyc存储器中的内容,只存储旧状态 我也在web浏览器上这样做过,看到了同样的情况,应用程序中的状态更新很好,然后当我检查存储时,没有任何更改,它仍然将'initialState'变量作为状态,并且更新没有添
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<ThemeProvider theme={theme}>
<AppGateway />
</ThemeProvider>
<StatusBar style="auto" />
</PersistGate>
</Provider>
减速机/鸭子
const CREATEUSER = 'createuser'
export const createUser = ({name, id, email}) => ({
type: CREATEUSER,
payload: {
id,
name,
email,
created_account: Math.floor(Date.now() / 1000),
last_login: Math.floor(Date.now() / 1000),
}
})
function userReducer (state = initialState, action) {
switch (action.type) {
case CREATEUSER:
return {...state, account:{...state.account, ...action.payload} }
break;
default:
return state
}
}
export default userReducer;
还有我的配置
import {createStore , combineReducers} from 'redux'
import userReducer from './ducks/user'
import { persistStore, persistReducer } from 'redux-persist'
// import AsyncStorage from 'redux-persist/lib/storage'
import AsyncStorage from '@react-native-async-storage/async-storage';
const reducer = combineReducers({
user: userReducer
})
const persistConfig = {
key: 'root',
storage: AsyncStorage,
}
const persistedReducer = persistReducer(persistConfig, reducer)
export default () => {
let store = createStore(persistedReducer)
let persistor = persistStore(store)
return { store, persistor }
}
import {createStore , combineReducers} from 'redux'
import userReducer from './ducks/user'
import { persistStore, persistReducer } from 'redux-persist'
// import AsyncStorage from 'redux-persist/lib/storage'
import AsyncStorage from '@react-native-async-storage/async-storage';
const reducer = combineReducers({
user: userReducer
})
const persistConfig = {
key: 'root',
storage: AsyncStorage,
}
const persistedReducer = persistReducer(persistConfig, reducer)
export default () => {
let store = createStore(persistedReducer)
let persistor = persistStore(store)
return { store, persistor }
}