I would like to use code I am already using little bit differently. I have critical data stored in the state which has to be available straight after page reload, otherwise users will get logged out etc. To achieve this I am using this kind of function
window.addEventListener('onbeforeunload', store.dispatch(setDataAfterBrowserRefresh()));
Inside that function though, I would like to be able to access the state how it is/was just before the page reload/refresh. (Currently I am kind of only reloading everything again) So I am asking is it a bad practice to write something like this inside my app.jsx and another file:
app.jsx
export const store = createStore(
connectRouter(history)(rootReducer),
{},
composeEnhancers(
applyMiddleware(
routerMiddleware(history),
thunk))
);
BrowserRefreshHandlerFile.js
import { store } from '../app.jsx';
some code in between and then
store.getState().partOfStateIWantToAccess
I have gotten used to access the store only by using props inside connected components and by using action dispatchers and all that, and not "directly" within some js code.
Any comments and thoughts are welcome.