繁体   English   中英

React state 作为道具传递,不会在子组件中更新

[英]React state passed as prop does not update in child component

Hi I wonder is someone could explain why when the returned zones of each function, are passed down to a child as props, the first function updates the props and renders the child, but a small change in the second function targeting the exact values required does不是? 我想我可能会以某种方式丢失原始参考,但不知道如何修复。 提前致谢

getAudioControls1(controls,rooms){    
    let zones = []

    for (const key in controls) {
        if (controls.hasOwnProperty(key)) {
            const element = controls[key];
            if (element.type === "InfoOnlyText" && element.name === "Synched") {   
                let room = this.getReqRoom(element.room, rooms)
                element.roomName = room.name
                zones.push(element)
            }
        }
    }    
    return zones
}
getAudioControls2(controls,rooms){
    let zones = []
    for (const key in controls) {
        if (controls.hasOwnProperty(key)) {
            const element = controls[key]; 
            if (element.type === "InfoOnlyText" && element.name === "Synched") {     
                let room = this.getReqRoom(element.room, rooms)
                let rawZones = []
                element.roomName = room.name
                rawZones.push(element.roomName,element.statesValue.text)
                zones.push(rawZones)
            }
        }    
    }
    return zones
}

在第一个示例中,您将element (我猜它是一个对象)推送到zones 结果,您拥有对象数组。

在第二个中,您将数组rawZones推送到您的zones 结果,您有 arrays 数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM