client/src/components/main/Door.js
//We only keep the 30 last received data in the state
We only keep the 30 last received data in the state
We only keep the 30 last received data in the state
loadData(data) {
        console.log("From Arduino: ", data)
        if (data.type === "getState") {
            this.setState({
                open: data.state
            })
        } else if (data.type === "openClose") {
            let newDatas = this.state.datas;
            if(this.state.datas.length >= 30) { newDatas.shift(); }
            newDatas.push(data) 
            this.setState({
                datas: newDatas,
                open: data.open
            })
        }
    }
loadData ( data ) { console . log ( "From Arduino: " , data ) if ( data . type === "getState" ) { this . setState ( { open : data . state } ) } else if ( data . type === "openClose" ) { let newDatas = this . state . datas ; if ( this . state . datas . length >= 30 ) { newDatas . shift ( ) ; } newDatas . push ( data ) this . setState ( { datas : newDatas , open : data . open } ) } }
We only keep the 30 last received data in the state
We only keep the 30 last received data in the state
// ajoute data à la fin du tableau 