How to dynamically assign each button to change color on click

3655 views react-native
-3

I have a group of buttons as the following picture :

8 sample buttons

I want to know how I can use react native to individually and dynamically change their color onPress

answered question

1 Answer

12

use stateful component.

Because I avoided the class keyword, I would use recompose, add a new state using withState(). you need to call compose() with your button component.

during onPress, you can have something like,

onPress={ ()=> setStateColor(randomColor()) }

posted this

Have an answer?

JD

Please login first before posting an answer.