3

I stuck at the "Storing a history" part of the tutorial, trying to pull state up from Board to Game. I've removed constructor from Board and was trying to change Board so that it takes squares via props:

 renderSquare(i) {
    return <Square value={this.props.squares[i]} onClick={() => this.props.onClick(i)} />;
  }

but it fails..

code: https://codepen.io/gka/pen/eBgapz

0

2 Answers 2

5

In your example, you pass in squares as props. So you need to change

renderSquare(i) {
    return (
      <Square 
        value={this.props.squares[i]}
        onClick={() => this.props.onClick(i)}
      />;
    );
}

into

renderSquare(i) {
    return (
      <Square 
        value={this.props[i]}
        onClick={() => this.props.onClick(i)}
      />;
    );
}

Because this.props already refers to the squares you passed in.

Sign up to request clarification or add additional context in comments.

Comments

0

I had my App render Board instead of Game, so that was the reason it wasn't working.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.