Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. hanldeClick(index){
  2. var x;
  3. const newGames = this.state.games.slice();
  4. if(this.state.games[index].selected) {
  5. newGames[index].selected = false;
  6. x = -1;
  7. }
  8. else {
  9. newGames[index].selected = true;
  10. x = 1;
  11. }
  12. this.setState({games: newGames, selected: this.state.selected + x});
  13. }
  14. renderGames(){
  15. var arr = [];
  16. const res = [];
  17. const len = this.state.games.length;
  18. var index = 0;
  19. for(let i=0; i<Math.ceil(len/3); i++){
  20. for(let j=0; j<3; j++){
  21. if(index>=len)
  22. break;
  23. var style = this.state.games[index].selected ? "active" : "inactive";
  24. arr.push(
  25. <Col key={index}>
  26. <img
  27. onClick={()=>{this.hanldeClick(index)}}
  28. className={style}
  29. src={this.state.games[index].image}
  30. alt={this.state.games[index].description}
  31. />
  32. </Col>
  33. );
  34. index++;
  35. }
  36. if(index<=len){
  37. res.push(<Row key={i} className='margin'>{arr}</Row>);
  38. arr = [];
  39. }
  40. }
  41. return res;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement