简体   繁体   中英

React Native - Multiple countdown timers in one view with out re-rendering

I am building an app that has a screen in a stack navigator that renders multiple touchableOpacity's, all with an independent and unique countdown timer in seconds.

Each TouchableOpacity displays the remaining seconds in the count by subtracting the difference of the unique time and current time. The current time is stored as a state variable and when the component mounts, the function below is called.

    initTime() {
        setInterval( () => {
            this.setState({
                currentTime : new Date()
            })
          },1000)
    }

My issue is mainly performance, the view needs to re-render every second which causes older devices to really struggle with the constant rendering.

Is there any way I can achieve this without needing to re-render every second?

Simply create a count down component separately and import it anywhere. this component only updates himself and has not any issue on the parent view. I checked this method for about 100 components in one view and has not any problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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