输入元素不应从受控状态切换到非受控状态(反之亦然)。 React.js

时间:2020-08-10 17:45:59

标签: reactjs mern

我使用MERN堆栈从github克隆了一个简单的CRUD应用程序项目。我试图在现有类别中添加“语言”类别:“用户名”,“描述”,“持续时间”和“日期”。我遍历了代码并添加了类似于其他类别设置语言的语言,但是当我尝试编辑现有帖子以添加语言时,出现此错误。

import sys
import random
import time

rounds=0

def user1bot(rounds):
    print("")
    input("Enter A to roll the Dice!")
    userscore=random.randint(1,6)
    print("You Scored: "+str(userscore))
    rounds=rounds+1
    print(rounds)
    userbot(rounds)

def userbot(rounds):
    print("Bot is rolling a dice...")
    time.sleep(3)
    userscorebot=random.randint(1,6)
    print("Bot Scored: "+str(userscorebot))
    rounds=rounds+1
    print(rounds)
    user1bot(rounds)

while rounds<5:
    user1bot(rounds)
    continue
else:
    sys.exit()
    

我对为什么在Warning: A component is changing a controlled input of type text to be uncontrolled. Input elements should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. in input (at edit-exercise.component.js:156) in div (at edit-exercise.component.js:154) in form (at edit-exercise.component.js:109) in div (at edit-exercise.component.js:107) in EditExercise (created by Context.Consumer) in Route (at App.js:18) in div (at App.js:14) in Router (created by BrowserRouter) in BrowserRouter (at App.js:13) in App (at src/index.js:7) in StrictMode (at src/index.js:6) 处收到此错误感到困惑,因为代码的设置与持续时间相同,而持续时间仅比第156行稍高,并且持续时间没有错误。

我查了一下这个错误并读了几篇文章,看来正在发生的事情是语言持有一个空值或类似的东西,我不确定为什么其余的代码仍能正常工作收到错误。

edit-exercise.component.js:

edit-exercise.component.js:156

0 个答案:

没有答案