Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React Basics Introducing Props Use Props to Create Reusable Components

Uche Onuekwusi
Uche Onuekwusi
16,759 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,785 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.