How to access react-redux store outside of component

Tuomas Toivonen picture Tuomas Toivonen · Aug 18, 2016 · Viewed 8.3k times · Source

I have file which exports various utility functions to use across components, and these functions needs to access redux state. How do I import the state object to this file?

Answer

anoop picture anoop · Aug 18, 2016

connect does not work here if your utility functions are not react elements.

Best idea is, import create store and then use getState function,

import store from 'store/createStore';
const state = store.getState();