From the course: React Native Essential Training
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
Computing dynamic values where needed - React Native Tutorial
From the course: React Native Essential Training
Computing dynamic values where needed
- [Instructor] It's time for us to write code to determine if the game is won or lost. This means that while we're tapping on numbers we want to calculate the sum of the selected numbers. This sum is going to affect the game status. The game status can be one of three values. It can be the currently playing game status or it could be won, or it could be lost. The thing is this game status can be computed so we don't really need to put it on the state. So what I'm going to do is I'm going to create a new function here and call it game status. And the goal of this function is to compute the game status at any point. So the first thing that we need is the sum of selected number. Let's put that in a variable, call that sum selected. We can compute the sum of selected numbers from the selected IDs that we put on the state. Cause every time we select a number here we place its index ID on the state. In fact this selected…
Contents
-
-
-
-
-
(Locked)
Introduction and preview42s
-
(Locked)
Initializing the TargetSum app4m 36s
-
(Locked)
Configuring ESLint1m 47s
-
The game component with a random target3m 54s
-
(Locked)
Generating the random play numbers9m 41s
-
(Locked)
Styling the random play numbers2m 23s
-
(Locked)
Using TouchableOpacity for press events6m 17s
-
(Locked)
Changing UI based on selected numbers7m 31s
-
(Locked)
Adding shared behavior to numbers6m 21s
-
(Locked)
Using React DevTools with React Native4m 24s
-
(Locked)
Computing dynamic values where needed5m 14s
-
(Locked)
Changing UI based on game status4m 5s
-
(Locked)
Working with timers6m 16s
-
(Locked)
Caching to optimize computable values8m
-
(Locked)
Remounting a component to reset it7m 30s
-
(Locked)
-
-
-
-