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,501
  • 10
  • 25
OscarDev
  • 917
  • 14
  • 34

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
  • 29,664
  • 5
  • 45
  • 65