Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //file ./store/configureStore.js
- 'use strict';
- import {applyMiddleware, createStore} from 'redux';
- import thunk from 'redux-thunk';
- import reducers from '../reducers';
- import {persistStore, autoRehydrate} from 'redux-persist';
- import {AsyncStorage} from 'react-native';
- var myStore = applyMiddleware(thunk)(createStore);
- function configureStore(onComplete: ?() => void) {
- const store = autoRehydrate()(myStore)(reducers);
- persistStore(store, {storage: AsyncStorage, blacklist:['loginError']}, onComplete)
- return store;
- }
- // File setup.js
- 'use strict';
- import React from 'react-native';
- import App from './App';
- import { Provider } from 'react-redux';
- import configureStore from './store/configureStore';
- function setup() : React.Component {
- class Root extends React.Component {
- constructor() {
- super();
- this.state = {
- isLoading: true,
- // Note the callback
- store: configureStore(() => this.setState({isLoading: false})),
- };
- }
- render() {
- if (this.state.isLoading) {
- return null;
- }
- return (
- <Provider store={this.state.store}>
- <App />
- </Provider>
- );
- }
- }
- return Root;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement