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.

Adding shared behavior to numbers

Adding shared behavior to numbers - React Native Tutorial

From the course: React Native Essential Training

Start my 1-month free trial

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