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

New No-Code Track! 🚀start learning today!

🌟 Dreaming of a bright future? 🎓 Ask about the Treehouse Scholarship program! 🚀

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

  • Treehouse Logo
  • Plans
    Chevron
    • For Individuals
    • For Businesses
    • For Schools
    • For Libraries
    • For Military
  • Library
    Chevron
    • All Courses
    • Tracks
    • College Credit
  • Techdegree
    Chevron
    • Overview
    • Front End Development
    • Full Stack JavaScript
    • Data Analysis
    • UX Design
    • Python
  • Community
    Chevron
    • Code Adventures
    • Discord
    • Forum
    • Success Stories
    • Treehouse Links
    • 100 Days of Code
  • Resources
    Chevron
    • Career Toolbox
    • CodeForward
    • Free Treehouse Near Me
    • Jobs
    • Blog
    • Support
    • About
  • For Individuals For Businesses For Schools For Libraries For Military
  • All Courses Tracks College Credit
  • Overview Front End Web Development Full Stack JavaScript Python Development Data Analysis UX Design
  • Code Adventures Discord Forum Success Stories Treehouse Links 100 Days of Code
  • Career Toolbox CodeForward Free Treehouse Near Me Jobs Blog Support About
  • Sign In
  • Free Trial
Instagram Twitter Facebook YouTube LinkedIn
    • Newest
      • Newest
      • Active
      • Unanswered
      • Featured
    • All Topics
      • All Topics
      • • General Discussion
      • • AI
      • • Android
      • • 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
  • 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.

    Treehouse

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

See Full Catalogue

Techdegree

  • Front End Web Development
  • Full Stack JavaScript
  • Python Development
  • Data Analysis
  • UX Design

Tracks

  • Learn to Code for Beginners
  • Beginning Python
  • Beginning SQL
  • Beginning Java
  • ...see more

Courses

  • JavaScript Basics
  • Intro to HTML & CSS
  • Python Basics
  • CSS Layout
  • ...see more

Explore

  • Plans
  • Affiliates
  • Perks
  • Free Treehouse Near Me
  • Treehouse for Libraries
  • Treehouse for Businesses
  • Twitter
  • YouTube
  • Facebook
  • LinkedIn
  • Instagram
Terms & Conditions | Privacy

© 2025 Treehouse Island, Inc.