title: access redux persist outside components
body: <p>I'm trying to access a redux store with redux persist in a service for my react native app.</p>
  <p>I need a specific token to set a websocket connection.</p>
  <p>My code so far:</p>
  <p>./redux/Store.js:</p>
  <pre><code>const persistedReducer = combineReducers({
    tokens: persistReducer(secureConfig, TokensReducer),
  });
  
  const store = createStore(persistedReducer);
  
  const configureStore = () =&gt; {
    const persistor = persistStore(store);
  
    return { persistor, store };
  };
  
  export default configureStore;
  </code></pre>
  <p>./redux/reducers/TokenReducer</p>
  <pre><code>const initialState = {
    accessToken: null,
    refreshToken: null
  }
  
  const TokensReducer = (state = initialState, action) {
  // reducer
  };
  
  export default TokensReducer;
  </code></pre>
  <p>./service/websocket.js</p>
  <pre><code>import configureStore from '../redux/Store';
  
  const { store } = configureStore();
  
  console.log(store.getState().tokens);
  </code></pre>
  <p>The problem is, I'm not getting the persisted content, but I'm getting the initial state (accessToken = null, refreshToken = null).</p>
  <p>When I access the store from inside my app (inside components inside  and ), I get the correct values.</p>
  <p><strong>Edit:</strong></p>
  <p>when I wrap the console.log in a setTimeout() of let's say 1 second, it works! So it asynchronous, but how can I create my code to wait for it and not using setTimeout?</p>