Skip to main content

🚀 In our NEW AI Bootcamp you'll build a working app in 28 days, no experience required. Free to all subscription levels.

✨ Earn college credits in Cybersecurity, JS, HTML, CSS and Python

Join the Treehouse affiliate program and earn 25% recurring commission! 🤑

  • Treehouse Logo
    • For Individuals
    • For Businesses
    • For Schools
    • For Libraries
    • For Military
    • All Courses
    • Tracks
    • AI Bootcamp
    • College Credit
    • Techdegree Bootcamps
    • Front End Development
    • Full Stack JavaScript
    • Code Adventures
    • Discord
    • Forum
    • Success Stories
    • Treehouse Links
    • 100 Days of Code
    • Explore
    • Career Toolbox
    • Free Treehouse Near Me
    • Affiliates
    • Blog
    • Support
    • About
    • Learn
    • Beginner's Guide to Coding
    • Data Analysis with SQL & Python
    • Front-End Web Development
    • Python Programming Basics
    • Techdegree Bootcamp Overview
    • UX Design Fundamentals
    • AI Tools for Beginners
  • For Individuals For Businesses For Schools For Libraries For Military
  • All Courses Tracks AI Bootcamp College Credit
  • Techdegree Bootcamps Front End Web Development Full Stack JavaScript
  • Code Adventures Discord Forum Success Stories Treehouse Links 100 Days of Code
  • Explore Career Toolbox Free Treehouse Near Me Affiliates Blog Support About
    Learn Beginner's Guide to Coding Data Analysis with SQL & Python Front-End Web Development Python Programming Basics Techdegree Bootcamp Overview UX Design Fundamentals AI Tools for Beginners
  • Sign In
  • Free Trial
Instagram Twitter Facebook YouTube LinkedIn
Loading banner... Start your free trial at Treehouse
    • Newest
      • Newest
      • Active
      • Unanswered
      • Featured
    • All Topics
      • All Topics
      • • General Discussion
      • • AI
      • • APIs
      • • Coding for Kids
      • • College Credit
      • • Computer Science
      • • CSS
      • • Data Analysis
      • • Databases
      • • Design
      • • Development Tools
      • • Digital Literacy
      • • Game Development
      • • Go Language
      • • HTML
      • • Java
      • • JavaScript
      • • Learning Resources
      • • Machine Learning
      • • No-Code
      • • PHP
      • • Professional Growth
      • • Python
      • • Quality Assurance
      • • React
      • • Ruby
      • • Security
      • • Swift
      • • Vibe Coding
  • Victor Stanciu
    seal-mask
    .a{fill-rule:evenodd;}techdegree
    Victor Stanciu
    Full Stack JavaScript Techdegree Student 11,196 Points

    [After Video Update] So why not change `handleRemovePlayer` also, since it also mutates `prevState`?

    Posted March 16, 2022 8:56am by Victor Stanciu
    .a{fill-rule:evenodd;}techdegree
    Victor Stanciu
    Full Stack JavaScript Techdegree Student 11,196 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    0 Answers

  • Ruell Magpayo
    Ruell Magpayo
    508 Points

    accessing "score" directly from state as a member of Player allowed?

    Posted September 3, 2021 4:06am by Ruell Magpayo
    Ruell Magpayo
    508 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    0 Answers

  • Dinu Comendant
    Dinu Comendant
    6,049 Points

    confused of return {} and return()

    Posted July 28, 2021 2:47pm by Dinu Comendant
    Dinu Comendant
    6,049 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    0 Answers

  • Mahmoud Talass
    Mahmoud Talass
    9,274 Points

    nothing is making sense...

    Posted July 18, 2021 12:23am by Mahmoud Talass
    Mahmoud Talass
    9,274 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    2 Answers

  • James Crosslin
    seal-mask
    .a{fill-rule:evenodd;}techdegree seal-36
    James Crosslin
    Full Stack JavaScript Techdegree Graduate 16,882 Points

    Disagree with the new index prop, also my solution uses Hooks instead of classes

    Posted March 19, 2021 8:34pm by James Crosslin
    .a{fill-rule:evenodd;}techdegree seal-36
    James Crosslin
    Full Stack JavaScript Techdegree Graduate 16,882 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    2 Answers

  • Eduardo Osorio
    seal-mask
    .a{fill-rule:evenodd;}techdegree seal-36
    Eduardo Osorio
    Full Stack JavaScript Techdegree Graduate 20,847 Points

    I think this would be a less verbose alternative, that doesn't mutate the previous state directly.

    Posted March 12, 2021 8:40pm by Eduardo Osorio
    .a{fill-rule:evenodd;}techdegree seal-36
    Eduardo Osorio
    Full Stack JavaScript Techdegree Graduate 20,847 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    0 Answers

  • cloud712
    cloud712
    7,616 Points

    Why is let index = props.index; outside of the return? Could we not use props.index within the onClick attribute?

    Posted November 27, 2020 7:11am by cloud712
    cloud712
    7,616 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    2 Answers

  • newwebcoder
    newwebcoder
    13,061 Points

    setState with "+=" instead of just "+"

    Posted June 30, 2020 6:01pm by newwebcoder
    newwebcoder
    13,061 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    1 Answer

  • Michael Cook
    seal-mask
    .a{fill-rule:evenodd;}techdegree seal-36
    Michael Cook
    Full Stack JavaScript Techdegree Graduate 28,975 Points

    My approach to updating score

    Posted May 23, 2020 9:20pm by Michael Cook
    .a{fill-rule:evenodd;}techdegree seal-36
    Michael Cook
    Full Stack JavaScript Techdegree Graduate 28,975 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    1 Answer

  • Rishi B
    Rishi B
    13,866 Points

    why player props are shown 'undefined'?

    Posted April 18, 2020 2:30am by Rishi B
    Rishi B
    13,866 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    0 Answers

  • Rishi B
    Rishi B
    13,866 Points

    how do i get rid of 'Cannot read property 'toString' of undefined' error?

    Posted April 13, 2020 1:38pm by Rishi B
    Rishi B
    13,866 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    2 Answers

  • Marius Adam
    Marius Adam
    1,736 Points

    onClick 1 and -1 to 0.5 and -0.5 otherwise increment by 2???

    Posted April 9, 2020 7:14pm by Marius Adam
    Marius Adam
    1,736 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    4 Answers

  • fairest
    seal-mask
    .a{fill-rule:evenodd;}techdegree seal-36
    fairest
    Full Stack JavaScript Techdegree Graduate 19,303 Points

    Isn't it better to use React Hooks?

    Posted January 18, 2020 11:32pm by fairest
    .a{fill-rule:evenodd;}techdegree seal-36
    fairest
    Full Stack JavaScript Techdegree Graduate 19,303 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    1 Answer

  • Francois Martin
    Francois Martin
    1,958 Points

    I don't understand where the index number comes from, it looks like its a cycle that is never set?

    Posted September 4, 2019 6:24am by Francois Martin
    Francois Martin
    1,958 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    1 Answer

  • Brandyn Lordi
    Brandyn Lordi
    17,778 Points

    Why change player score using new index variable instead of the key which is already defined in players array?

    Posted June 21, 2019 3:47am by Brandyn Lordi
    Brandyn Lordi
    17,778 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    5 Answers

  • rashell smith
    rashell smith
    15,405 Points

    My Delta Is undefined

    Posted June 18, 2019 2:10am by rashell smith
    rashell smith
    15,405 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    1 Answer

  • Moe Ghashim
    Moe Ghashim
    11,109 Points

    Why did we wrap the code block in handleScore with parenthesis?

    Posted March 24, 2019 9:33am by Moe Ghashim
    Moe Ghashim
    11,109 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    1 Answer

  • liamthornback2
    liamthornback2
    9,618 Points

    How does the setState method know what player's score to change?

    Posted October 26, 2018 3:01pm by liamthornback2
    liamthornback2
    9,618 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    11 Answers

  • liamthornback2
    liamthornback2
    9,618 Points

    Is is possible to use a function that returns a function to make your code more concise?

    Posted October 26, 2018 2:47pm by liamthornback2
    liamthornback2
    9,618 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    1 Answer

  • Lean Flores
    Lean Flores
    34,939 Points

    Is it safe to mutate prevState? i.e. prevState.players[index].score += delta

    Posted October 4, 2018 9:03pm by Lean Flores
    Lean Flores
    34,939 Points
    • JavaScript
    • React Components (2018)
    • Managing State and Data Flow
    • Update State Based on a Player's Index

    14 Answers

Posting to the forum is only allowed for members with active accounts.
Please sign in or sign up to post.

Techdegree

  • Front End Web Development
  • Full Stack JavaScript
SEE ALL

Tracks

  • Learn to Code for Beginners
  • Beginning Python
  • Beginning SQL
  • Beginning Java
SEE ALL

Courses

  • JavaScript Basics
  • Intro to HTML & CSS
  • Python Basics
  • CSS Layout
SEE ALL

About Us

  • About
  • Blog
  • Community
  • Stories
  • Contact
  • Gift Card

Explore

  • Plans
  • Affiliates
  • Perks
  • Shop
  • Free Treehouse Near Me
  • Treehouse for Libraries
  • Treehouse for Businesses

Treehouse is an online technology education platform founded in 2011. Treehouse offers more than 700 self-paced, video-based courses in web development, programming, data analysis, design, and AI, plus two project-based bootcamp programs in Front End Web Development and Full Stack JavaScript. Individual Treehouse plans start at $25 per month and include a 7-day free trial. Treehouse serves individual learners, businesses, schools, and public libraries. Cardholders at participating U.S. public libraries can use Treehouse for free. Select Treehouse courses, offered with University Pathways International, are recommended for college credit by ACE and NCCRS. Treehouse learners earn digital certificates for completed Tracks.

Terms & Conditions · Privacy · © 2026 Treehouse Island, Inc.
  • Twitter
  • YouTube
  • Facebook
  • LinkedIn
  • Instagram
  • Discord