Hello, please see code example below and the arguments to createSelector in getFruitNames() and getAltFruitNames(). I haven't seen any example that explains why the last function is correct:
import { createSelector } from 'reselect';
import { fromJS } from 'immutable';
const state = fromJS({
tree: {
fruit: [
{ name: 'apple' },
],
}
});
const getTree = (state) => state.get('tree');
const getFruit = () => createSelector(
getTree,
(tree) => tree.get('fruit')
);
const getFruitNames = () => createSelector(
getFruit, // function name
(fruit) => {
console.log(fruit); // Selector class object -> NOT OK!
return fruit.map((f) => f.get('name'));
}
);
const getAltFruitNames = () => createSelector(
getFruit(), // <-- function call?!
(fruit) => {
console.log(fruit); // Immutable.List object -> OK!
return fruit.map((f) => f.get('name'));
}
);
Reselect: 2.5.4
const getFruit = () => createSelector(... creates a function that returns a selector. None of those () => should be there, just const selectorName = createSelector(....
Most helpful comment
const getFruit = () => createSelector(...creates a function that returns a selector. None of those() =>should be there, justconst selectorName = createSelector(....