Can I get data from a Redux store by using useSelector()
but outside the functional component in ReactJS?
I try using useSelector()
as an ordinary function but it returns an an error because useSelector()
is running outside of the functional react component.
Import your store, then call getState()
to access the current state. For example:
import store from './mystore.js';
// ...
const someData = store.getState().data;