0

I've started learning selectors and redux. The state of the app looks as follows:

State unfolded

And then unfolded:

enter image description here

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

Wasteland
  • 4,889
  • 14
  • 45
  • 91

1 Answers1

1

You are passing wrong value to your selector. Change values: getSelected(state.grid) to values: getSelected(state) in your mapStateToProps.

fkulikov
  • 3,169
  • 13
  • 24