From the course: React Native Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Caching to optimize computable values

Caching to optimize computable values - React Native Tutorial

From the course: React Native Essential Training

Start my 1-month free trial

Caching to optimize computable values

- [Instructor] In the previous video, we implemented an interval timer to limit the time a user has to play the game. And we identified that the computation of the gameStatus is now not needed every second, but rather when a number is clicked or when the timer hits zero. To optimize this computation, we need to cache it. Let's do that. Instead of this.gameStatus as a function, I'm going to assume the gameStatus is a fixed number that I have cached on the instance. This gameStatus start with playing. So in here I'll introduce a gameStatus instance property. And this one starts with playing. And now I need to change this gameStatus, the cached copy of the computed value. I need to change that when needed. And I can do so in componentWillUpdate. This life cycle method happens right before the render method. When the component is about to be updated. When the state of the component is different, or when the props of the…

Contents