1

Technology :

  • ReactJS

Todo :

  • When user chooses a number I need to change just the background style.
  • The style is only maintained if this.state.currentPage === number, otherwise it does not show any style although I require the styles changing the background.

Tried Case :

 onClick={this.handleClick} style={this.state.currentPage === number ?
 styles.paginationButtons : [styles.paginationButtons,
 {backgroundColor:'blue'}]}>
Abhishek Kumar
  • 2,365
  • 9
  • 23
OscarDev
  • 801
  • 10
  • 28

1 Answers1

2

Try updating your code so that you supply the dynamic styles to your component without the use of arrays.

You should be able to do so in this way:

style={ (this.state.currentPage === number ? styles.paginationButtons : { backgroundColor:'blue', ...styles.paginationButtons }) }
Dacre Denny
  • 28,232
  • 5
  • 37
  • 57