Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Building Applications with React and Redux Putting it all Together Connecting the Scoreboard Container to Redux

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

initialState undefined

Hi all,

My Git shell is compiling the project in it's current state with npm start but there's a console error in the browser that says

players.js:1 Uncaught ReferenceError: initialState is not defined
    at Player (players.js:1)
    at dispatch (createStore.js:178)
    at createStore (createStore.js:253)
    at Object.<anonymous> (index.js:13)
    at Object.<anonymous> (bundle.js:8523)
    at Object.<anonymous> (bundle.js:8524)
    at __webpack_require__ (bootstrap 9b7cfae…:555)
    at fn (bootstrap 9b7cfae…:86)
    at Object.<anonymous> (bootstrap 9b7cfae…:578)

I've tried to flush this bug out but I'm out of ideas. Could someone take a quick look? :)

As of now...repo out of date... https://bitbucket.org/jg_digitalMedia/react-redux

3 Answers

Matthew Caloger
Matthew Caloger
12,903 Points

I noticed that your actiontypes/player.js file differs greatly from the source file from the course, may be related to the issue:

Your actiontypes/player.js:

import * as PlayerActionTypes from '../actiontypes/player';
import * as PlayerReducers from '../reducers/players';

const initialState = [
    {
      name: 'Jim Hoskins',
      score: 31,
    },
    {
      name: 'Andrew Chalkley',
      score: 20,
    },
    {
      name: 'Alena Holligan',
      score: 50,
    },
];

Source actiontypes/player.js:

export const ADD_PLAYER = 'player/ADD_PLAYER';
export const REMOVE_PLAYER = 'player/REMOVE_PLAYER';
export const UPDATE_PLAYER_SCORE = 'player/UPDATE_PLAYER_SCORE';

Maybe change it and give it a try? with the changes i gave in my original post, we're creating an initialState right in that file so it should be getting picked up.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi Matthew,

I couldn't for the life of me workout where the problem was but I think what's happened is that that I mixed up the redicer and actions file and neglected to actually declare my action types. So it's taken me a while but I've updated my repo to a working state and I should be able to go on from here even though I'm still a video behind :)

Thanks for trying!!

I'm having the same issue....

Matthew Caloger
Matthew Caloger
12,903 Points

I believe you are missing the following on the top of /src/reducers/Players.js:

import * as PlayerActionTypes from '../actiontypes/player';

const initialState = [
  {
    name: 'Jim Hoskins',
    score: 31,
  },
  {
    name: 'Andrew Chalkley',
    score: 20,
  },
  {
    name: 'Alena Holligan',
    score: 50,
  },
];

I apologize if that doesn't work, as I haven't done the React course yet, but the reducers folder was the only "players.js" file, looking at the final files for "Intro to Reducers" shows the import and initialState const to be the only difference between the code and your file uploaded on Bitbucket.

Good luck!

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Thanks for you reply Matthew. But, sorry it didn't work. :-)

I'm going to keep trying though. There must be something simple I'm missing :)

Matthew Caloger
Matthew Caloger
12,903 Points

Is there a new error message you're receiving?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

nope, same one! :)

It's just not picking up initialState for whatever reason. It shouldn't be an issue anyway really, so long as I'm importing the right files and I'm confident I am :-)