peter-mach / react-navigation-is-focused-hoc

Ready to use solution using HOC to expose props.isFocused for react-navigation. No Redux needed.
MIT License
169 stars 21 forks source link

how to integrate it with Provider & PersistGate #15

Open alainib opened 6 years ago

alainib commented 6 years ago

Steps to reproduce

this is my actual code :

store.js

import { createStore, compose, applyMiddleware } from 'redux';
import { persistStore, persistCombineReducers } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import { createLogger } from 'redux-logger';
import rootReducers from "test/src/redux/reducers";

const config = {
  key: 'root',
  storage,
};
const middleware = [];

const reducers = persistCombineReducers(config, rootReducers);
const enhancers = [applyMiddleware(...middleware)];
const initialState = {};
const persistConfig = { enhancers };
const store = createStore(reducers, undefined, compose(...enhancers));
const persistor = persistStore(store, persistConfig, () => {});
const configureStore = () => {
  return { persistor, store };
}

export default configureStore;

App.js

import configureStore from "test/src/redux/store";
const { persistor, store } = configureStore();

const MyTabView = TabNavigator({ ... });

export default class App extends React.PureComponent {
 ...    
 render() {
    return (
      <Provider store={store}>
        <PersistGate
          loading={<ActivityIndicator />}
          persistor={persistor}>
            <MyTabView />          
        </PersistGate>
      </Provider>
    );
  }
}

Expected behaviour

how to integrate your lib with Provider and PersistGate instead of AppNavigator

Environment

react-navigation-is-focused-hoc

Version: npm version or "master"