Why can't I push values in my state array in react.js?

前端 未结 5 937
后悔当初
后悔当初 2021-01-15 09:40

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 f

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-15 10:22

    The problem is over here );

    When you run this.addScore(this.state.scoreInput) inside the onclick, javascript runtime will call addScore function. Thats why you are getting 50~logs

    Try );

提交回复
热议问题