Wasteland
Wasteland

Reputation: 5399

Redux - selectors not accessing state

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

Upvotes: 0

Views: 1069

Answers (1)

fkulikov
fkulikov

Reputation: 3199

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

Upvotes: 1

Related Questions