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'}]}>
2

1 Answer 1

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 }) }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.