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 Actions, Dispatch, and Reducers. Oh my! Intro to Reducers

Jonas Wu
Jonas Wu
13,928 Points

why name: action.name?

Hellooo :)

I'm a beginner of React. And I'd like to know why we use {name: action.name} as the new state while adding new player instead of using {name:name} ?

1 Answer

Hi Jonus Wu, As we're only provided the state and action objects as arguments for our reducers, we have to extract the player name from the action item (which we haven't seen yet). That player name is stored in the action object under the key name, so action.name is appropriate. The variable name is not defined in the scope of our function.