React setState无法修改Array

时间:2019-02-13 00:37:24

标签: javascript reactjs

在我的组件中进行了装载:

 import random

 asciiRange = list(range(33,128))
 hKey = [ord(c) for c in "AABBCCDDEE"]

 val = 508
 while True:
     result = 0
     key = random.choice(asciiRange)
     for i in hKey:
         result += i ^ key
         if result > val:
             break
     print(result, end=' ')
     if result == val:
         break

我打印componentDidMount(){ let tempKeyArray = []; for (let key in this.state.list){ tempKeyArray.push(this.state.list[key].keyword); } this.setState({keywords: [...tempKeyArray]}); console.log(this.state.keywords, tempKeyArray); } 时,通过给我一个看起来像这样的字符串,结果可以很好地工作: tempKeyArray

但是,["abaya", "water", "can", "flash light", "band aid", "battery"]仅打印一个空数组(这是它的默认值)。我做错了什么?

任何帮助表示赞赏!

0 个答案:

没有答案