mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-21 21:49:55 +03:00
Add PersistGate
This commit is contained in:
parent
4bf728ea66
commit
f77420c94c
|
@ -1,33 +1,34 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
import { Store } from 'redux';
|
import { Store } from 'redux';
|
||||||
|
import { Persistor } from 'redux-persist';
|
||||||
|
import { PersistGate } from 'redux-persist/integration/react';
|
||||||
import configureStore from './store/configureStore';
|
import configureStore from './store/configureStore';
|
||||||
import { CONNECT_REQUEST } from './constants/socketActionTypes';
|
import { CONNECT_REQUEST } from './constants/socketActionTypes';
|
||||||
import App from './containers/App';
|
import App from './containers/App';
|
||||||
import { StoreState } from './reducers';
|
import { StoreState } from './reducers';
|
||||||
import { ConnectionOptions, StoreAction } from './actions';
|
import { StoreAction } from './actions';
|
||||||
|
|
||||||
interface Props {
|
class Root extends Component {
|
||||||
socketOptions?: ConnectionOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Root extends Component<Props> {
|
|
||||||
store?: Store<StoreState, StoreAction>;
|
store?: Store<StoreState, StoreAction>;
|
||||||
|
persistor?: Persistor;
|
||||||
|
|
||||||
UNSAFE_componentWillMount() {
|
UNSAFE_componentWillMount() {
|
||||||
this.store = configureStore();
|
const { store, persistor } = configureStore();
|
||||||
this.store.dispatch({
|
this.store = store;
|
||||||
|
this.persistor = persistor;
|
||||||
|
store.dispatch({
|
||||||
type: CONNECT_REQUEST,
|
type: CONNECT_REQUEST,
|
||||||
});
|
});
|
||||||
this.forceUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.store) return null;
|
if (!this.store) return null;
|
||||||
const AppAsAny = App as any;
|
|
||||||
return (
|
return (
|
||||||
<Provider store={this.store}>
|
<Provider store={this.store}>
|
||||||
<AppAsAny {...this.props} />
|
<PersistGate loading={null} persistor={this.persistor!}>
|
||||||
|
<App />
|
||||||
|
</PersistGate>
|
||||||
</Provider>
|
</Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,6 @@ export default function configureStore() {
|
||||||
persistedReducer as any,
|
persistedReducer as any,
|
||||||
composeEnhancers(applyMiddleware(exportState, api))
|
composeEnhancers(applyMiddleware(exportState, api))
|
||||||
);
|
);
|
||||||
persistStore(store);
|
const persistor = persistStore(store);
|
||||||
return store;
|
return { store, persistor };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user