import store from './store'
let reduxStore = ''
store.subscribe(() => {
  reduxStore = store.getState().username
  console.log(reduxStore) // I get USERNAME
})
console.log(reduxStore) // I get undefined
Is there a way to save reduxStore to global variable so I can use outside of store.subscribe function?
Thank you!
Just assign the store you created to window:
const store = createStore(reducers, preloadedState);
// ...
window.reduxStore = store;
Then you can access the store from anywhere via for instance:
window.reduxStore.getState().username
However, I can't think of any valid reason for this to be necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With