0

I'm using react-boilerplate that uses reselect for reading the redux state and maps it to props. I am trying to read the redux state outside a react component (say in custom function defined in myUtil.js).

There is selector in selectors.js:

const makeSelectLoading = () =>   createSelector(selectGlobal, globalState => globalState.get('loading'));

I import makeSelectLoading into myUtil.js and try to print the value using console.log(makeSelectLoading()). I am expecting the value of the Loading state variable, instead I'm getting the below:

myUtil.js?d403:14 ƒ () {
    if (!areArgumentsShallowlyEqual(equalityCheck, lastArgs, arguments)) {
      // apply arguments instead of spreading for performance.
      lastResult = func.apply(null, arguments);
    } 

Should I expect this to work? If not, any ideas where I'm going wrong? Thanks!

1 Answers1

0

makeSelectLoading is not a selector itself but a selector factory: a function which returns an actual selector.

In order to use it you should get a selector instance from it and then call the returned instance with the expected arguments.

const getSelectLoading = makeSelectLoading();
const loadingState = getSelectLoading(state);
Andrea Carraro
  • 9,731
  • 5
  • 33
  • 57
  • Thanks, Andrea! The challenge I'm facing is reading the redux state from the store in cases when the 'state' is not supplied automatically as in the case selectors.js. The store is configured in configureStore.js, and passed in through Provider to components. However, what is the right way of reading from the state outside of this? – codemasorete Aug 24 '18 at 13:55