Advertisement
Guest User

react if else rendering

a guest
Aug 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component, useEffect, useState } from "react";
  2. import ReactDOM from "react-dom";
  3. import "../../css/components/Example.css";
  4. import Card from "./Card";
  5.  
  6. export default class Example extends Component {
  7.     constructor(props) {
  8.         super(props);
  9.  
  10.         this.state = {
  11.             active_campaign: [
  12.                 {
  13.                     image: "http://mysadaqah.test/assets/img/header-bg.jpg",
  14.                     title: "testing",
  15.                     content: "try",
  16.                     proggressWidth: "25%",
  17.                     progress: 25
  18.                 },
  19.                 {
  20.                     image: "http://mysadaqah.test/assets/img/header-bg.jpg",
  21.                     title: "testing",
  22.                     content: "try",
  23.                     proggressWidth: "25%",
  24.                     progress: 25
  25.                 },
  26.                 {
  27.                     image: "http://mysadaqah.test/assets/img/header-bg.jpg",
  28.                     title: "testing",
  29.                     content: "try",
  30.                     proggressWidth: "25%",
  31.                     progress: 25
  32.                 },
  33.                 {
  34.                     image: "http://mysadaqah.test/assets/img/header-bg.jpg",
  35.                     title: "testing",
  36.                     content: "try",
  37.                     proggressWidth: "25%",
  38.                     progress: 25
  39.                 }
  40.             ]
  41.         };
  42.     }
  43.  
  44.     render() {
  45.         return (
  46.             <div className='container'>
  47.                 <div
  48.                     className='row justify-content-center'
  49.                     style={{ padding: "40px" }}>
  50.                     <h2 style={{ textAlign: "center" }}> SENARAI KEMPEN </h2>
  51.                 </div>
  52.                 <div id='campaign_section'>
  53.                     <div className='row'>
  54.                         {this.state.active_campaign.map(item => {
  55.                             return (
  56.                                 // want to span <div className='row> here if index % 2 !== 0
  57.                                 <div className='col-md-6 card-container'>
  58.                                     <Card
  59.                                         image={item.image}
  60.                                         title={item.title}
  61.                                         content={item.content}
  62.                                         proggressWidth={item.proggressWidth}
  63.                                         progress={item.progress}
  64.                                     />
  65.                                 </div>
  66.                                 // want to span </div> here if index % 2 === 0
  67.                             );
  68.                         })}
  69.                     </div>
  70.                     <div
  71.                         className='row justify-content-center'
  72.                         style={{ paddingTop: "20px", marginBottom: "40px" }}>
  73.                         <a className='btn btn-primary btn-xl text-uppercase'>
  74.                             LIHAT SEMUA KEMPEN
  75.                         </a>
  76.                     </div>
  77.                 </div>
  78.             </div>
  79.         );
  80.     }
  81. }
  82.  
  83. if (document.getElementById("example")) {
  84.     ReactDOM.render(<Example />, document.getElementById("example"));
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement