Ant*_*jen 6 reactjs react-native react-redux
在 React Native 中使用 redux-persist v6 时,会导致点击事件和动画变得极其缓慢。点击按钮大约需要 5 或 6 秒才能执行操作。如果configureStore.ts我将 createStore() 更改为 takerootReducer而不是persistedReducer(并注释掉 index.tsx 中的 PersistGate),那么应用程序响应速度会再次加快。(仅供参考,应用程序的其余部分使用react-navigation。react-natigation-stack)
有没有人有任何建议可以让应用程序即使在使用 reduxPersist 时也能快速响应?
索引.tsx
import React from 'react';
import { Provider } from 'react-redux';
import { store, persistor } from './store/configureStore';
import { AppRegistry, View } from 'react-native';
import { MainNavigator } from './navigation/navigation';
import { PersistGate } from 'redux-persist/integration/react'
import { appId } from './config';
const App = () => {
return (
<Provider store={store} >
<PersistGate
loading={<View style={{ backgroundColor: '#ffc900' }} />}
persistor={persistor}>
<MainNavigator />
</PersistGate>
</Provider>
)
}
AppRegistry.registerComponent(appId, () => App);
Run Code Online (Sandbox Code Playgroud)
配置存储.ts
import AsyncStorage from '@react-native-community/async-storage';
import { createStore, compose, applyMiddleware } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import { rootReducer } from '../reducer/rootReducer';
import thunk from 'redux-thunk';
const persistConfig = {
key: 'root',
storage: AsyncStorage
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
let store = createStore(
persistedReducer, // rootReducer,
{},
compose(applyMiddleware(thunk))
)
let persistor = persistStore(store)
export { store, persistor }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1422 次 |
| 最近记录: |