简体   繁体   English

每当我更改状态变量时,React本机类都会重新渲染

[英]React native class re-renders every time when I change state variable

I am new to react-native and I'm working on a music player app. 我是React Native的新手,我正在开发音乐播放器应用。 I have a timer to update the value for a progress bar which indicates how much audio has been played. 我有一个计时器来更新进度条的值,该值指示已播放了多少音频。

When I update the timer value my whole class is re-rendered every seconds so I can not handle play, pause, and seek events. 当我更新计时器值时,我的整个班级每秒钟都会重新渲染一次,因此我无法处理播放,暂停和查找事件。

use shouldComponentUpdate to control the re-redering for example if you does not want to render component on Timer change 例如,如果您不想在Timer更改时呈现组件,请使用shouldComponentUpdate来控制重新渲染

shouldComponentUpdate(newProps, nextState) {
    if (nextState.timer !== this.state.timer) return false
    return true;
}

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

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