I can add 1 item to the array it logs ["50"] in the console. But when I try to add a second value I get this error "currentScores.push is not a function". Is this the wrong way of doing it?
class Scores extends Component {
constructor() {
super();
this.addScore = this.addScore.bind(this);
this.handleScoreChange = this.handleScoreChange.bind(this);
this.state = {
scores: [],
scoreInput: '',
};
}
addScore() {
const currentScores = this.state.scores;
const newScores = currentScores.push(this.state.scoreInput);
this.setState({ scores: newScores });
console.log(this.state.scores);
}
handleScoreChange(e) {
this.setState({ scoreInput: e.target.value });
}
render() {
const scores = this.state.scores;
return (
<input name="score" type="text" placeholder="Score" onChange={this.handleScoreChange}/>
<button onClick={this.addScore(this.state.scoreInput)}>add</button>
);
}
}
export default Scores;