From the course: React Native Essential Training
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
Adding shared behavior to numbers - React Native Tutorial
From the course: React Native Essential Training
Adding shared behavior to numbers
- [Instructor] Now we need to actually select the number when we press on it. To select a number, we just need to add its index right here in the selected numbers array that belongs to the state of the game component, which means the game component should have a function that does exactly that. So let's call this function select number, and is an arrow function that will modify the state. And to select the number just like is number selected, I need access to the number index to be selected. Again, I can't just select based on the number value, I need the number index. So this function is basically going to set the state. So it will return an object that has the new state. And inside this object, we are going to change the selected numbers array and basically push a new element to that selected numbers array. So I have options here, I can, for example, do something like selected numbers, and do the previous selected numbers…
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)
-
-
-
-