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 React Basics (2018) Introducing Props Use Props to Create Reusable Components

Uche Onuekwusi
Uche Onuekwusi
17,817 Points

My player component score is not changing

My player component score is not changing. it is fixed as when i set it at the counter component level . please see my code below

function Header(props) {
  console.log(props)
  return (
    <header>
      <h1>{props.title}</h1>
      <span className="stats">Player:{props.totalPoints}</span>
    </header>
  );
}

const Player = (props) => {
  return (
    <div className="player">
      <span className="player-name">
        {props.name}
      </span>
      <Counter score={99} />
    </div>
  );
}

const Counter = (props) => {
  return (
    <div className="counter">
      <button className="counter-action decrement"> - </button>
      <span className="counter-score">{props.score}</span>
      <button className="counter-action increment"> +</button>
    </div>
  );
}

const App = () => {
  return (
    <div className="scoreboard">
      <Header title="Scoreboard" totalPoints={0} />

      {/*Players list */}
      <Player name="Uchechukwu Onuekwusi" score={999} />
      <Player name="Uchechukwu Onuekwusi" />
      <Player name="Uchechukwu Onuekwusi" />
    </div>

  );
}

ReactDOM.render(
  <App />,
  document.getElementById("root")
)

Mod Edit: Fixed code formatting to be more readable. See comment below for how to do this.

rydavim
rydavim
18,813 Points

When posting code, there is some markdown you can use to make it more readable. If you wrap your code in three back-ticks you'll get special formatting, and you can optionally add the language for fancy syntax highlighting.

```language

Your code here!

```

// Your code here!
Cheo R
Cheo R
37,150 Points
<Player name="Uchechukwu Onuekwusi" score={999} />
<Counter score={99} />

Looks like you're hard-coding scores.