javascript - 在 React Native 中使用 '.splice()' 添加到数组
问题描述
我正在尝试.splice()
在状态函数中使用 to 和一个对象到一个数组。我拥有的代码来自一个可以编译的记分员应用程序。
state = {
team1: 'Team 1',
team2: 'Team 2',
score1: 0,
score2: 0,
team1Stats: [0, 0, 0],
team2Stats: [0, 0, 0],
date: 'Enter Date Here',
gameRecord: [
],
}
updateRanking = () => {
this.state.gameRecord.splice(this.state.gameRecord.length, 0, {
finalDate: this.state.date,
team1FinalScore: this.state.score1,
team2FinalScore: this.state.score2,
})
当我运行代码时,应用程序会运行,但是当我调用时,.updateRanking()
我收到一条错误消息:
错误不变违规:最小化 React 错误 #31
我必须改变什么?
解决方案
推荐阅读
- angular - 测试 jasmine 中的 ngIf 元素
- c++ - 如何在 C++ 中获取 Windows-1252 字符值?
- python - 树莓派 - Mac - PyCharm
- javascript - 当我单击轮播中的上一个或下一个按钮时更改 SVG 的填充
- mysql - MySQL CREATE USER 什么都不做
- asciidoc - 如何将列表或图像添加到目录 (TOC)
- templates - 如何创建一个函数来使用选定的模板启动 org-capture?
- html - 根据Angular中的输入长度添加多个复选框
- javascript - Python Selenium Scraping twitter 无限加载页面
- python - 是否可以将 pytest-bdd 与 SeleniumBase 一起使用?