Reputation: 5399
I've started learning selectors and redux. The state of the app looks as follows:
And then unfolded:
I'm trying to add a selector that would count the total of the sub-array first elements eg(6 + 4 + ..., etc), but first things first:
I've started writing a selector (for now just to display anything):
import { createSelector } from 'reselect';
const getValues = (state) => state.grid;
export const getSelected = createSelector(
[getValues],
grid => grid[0]
);
Then a container has:
const mapStateToProps = state => ({
score: state.score,
grid: state.grid,
values: getSelected(state.grid)
});
But I get an error: Cannot read property '0' of undefined.
The whole code can be seen here: https://github.com/wastelandtime/memgame
Please advise. Thank you
Upvotes: 0
Views: 1069
Reputation: 3199
You are passing wrong value to your selector. Change values: getSelected(state.grid)
to values: getSelected(state)
in your mapStateToProps
.
Upvotes: 1